Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load DLL 'freetype6' or one of its dependencies #32

Closed
mjolivet-lucca opened this issue Jan 3, 2023 · 5 comments
Closed

Unable to load DLL 'freetype6' or one of its dependencies #32

mjolivet-lucca opened this issue Jan 3, 2023 · 5 comments

Comments

@mjolivet-lucca
Copy link

Hello,

I tried to use Melville.Pdf on a .NET7 project (on a windows machine), and when testing the code in the readme, I had the following error :

System.TypeInitializationException: The type initializer for 'Melville.Pdf.Model.Renderers.FontRenderings.FreeType.GlobalFreeTypeResources' threw an exception.
 ---> System.DllNotFoundException: Unable to load DLL 'freetype6' or one of its dependencies: Le module spécifié est introuvable. (0x8007007E)
   at SharpFont.FT.FT_Init_FreeType(IntPtr& alibrary)
   at SharpFont.Library..ctor()
   at Melville.Pdf.Model.Renderers.FontRenderings.FreeType.GlobalFreeTypeResources.LoadFontLibrary()
   at Melville.Pdf.Model.Renderers.FontRenderings.FreeType.GlobalFreeTypeResources..cctor()
   --- End of inner exception stack trace ---
   at Melville.Pdf.Model.Renderers.FontRenderings.FreeType.FreeTypeFontFactory.FromCSharpStream(Stream source, Int32 index)
   at Melville.Pdf.Model.Renderers.FontRenderings.FreeType.FreeTypeFontFactory.FromStream(PdfStream pdfStream)
   at Melville.Pdf.Model.Renderers.FontRenderings.FreeType.FreeTypeFontFactory.FromStream(PdfStream pdfStream)
   at Melville.Pdf.Model.Renderers.FontRenderings.FontReader.CreateRealizedFont(PdfFont fontStreamSource, FreeTypeFontFactory factory)
   at Melville.Pdf.Model.Renderers.DocumentPartCaches.DocumentPartCache.FindAndStoreValue[T,TSource](TSource source, Func`2 creator)
   at Melville.Pdf.Model.Renderers.DocumentPartCaches.DocumentPartCache.Get[TSource,T](TSource source, Func`2 creator)
   at Melville.Pdf.Model.Renderers.RenderEngine.FontFromDictionary(PdfDictionary fontDic)
   at Melville.Pdf.Model.Renderers.RenderEngine.SetFont(PdfName font, Double size)
   at Melville.Pdf.LowLevel.Parsing.ContentStreams.ContentStreamContext.HandleOpCode(ContentStreamOperatorValue opCode)
   at Melville.Pdf.LowLevel.Parsing.ContentStreams.ContentStreamParser.RunOpcode(UInt32 opCode)
   at Melville.Pdf.LowLevel.Parsing.ContentStreams.ContentStreamParser.ParseReadResult(BufferFromPipe bfp)
   at Melville.Pdf.LowLevel.Parsing.ContentStreams.ContentStreamParser.Parse(PipeReader source)
   at Melville.Pdf.Model.Renderers.RenderEngine.RunContentStream()
   at Melville.Pdf.Model.Renderers.DocumentRenderers.DocumentRenderer.RenderPageTo(Int32 oneBasedPageNumber, Func`3 target)
   at Melville.Pdf.SkiaSharp.RenderWithSkia.ToSurfaceAsync(DocumentRenderer doc, Int32 oneBasedPageNumber, Int32 width, Int32 height)
   at Melville.Pdf.SkiaSharp.RenderWithSkia.ToPngStreamAsync(DocumentRenderer doc, Int32 oneBasedPageNumber, Stream target, Int32 width, Int32 height)

I use Melville.Pdf.SkiaSharp 0.2.0. It implicitely referenced SharpFont.NetStandard 1.0.5. I tried to also install SharpFont 4.0.1 but nothing changed.

@DrJohnMelville
Copy link
Owner

DrJohnMelville commented Jan 3, 2023 via email

@mjolivet-lucca
Copy link
Author

You are right, I am french, and I only have French language installed on my computer. Same for everything regarding format.

@DrJohnMelville
Copy link
Owner

I just installed a French version of windows 10 on a virtual machine. I can repro the bug exactly as you indicated above.

Let me setup a remote debugger and see if I can figure out what is going on.

@DrJohnMelville
Copy link
Owner

DrJohnMelville commented Jan 4, 2023

I now know what is going on. Freetype6 (as distributed by SharpFont) depends on MSVCRT120.dll. (A version of the microsoft visual C runtime.) I happened to have MSVCRT120.dll in my windows folder, and I will attach it to this comment.

The file is not present on the plain-vanilla/french image I have in the virtual machine. (I now suspect that the bug has nothing to do with language, and everything to do with being a plain-vanilla windows install.) If I copy MSVCRT120.dlll to the [App]\bin\debug\net7.0-windows\lib\x64 (which puts it right next to freetype6.dll) then everything works. I can break and fix the problem by adding or deleting that single file.
msvcr120.zip

I would really appreciate it if you could confirm that this hack makes it work on your machine as well.

This bug was reported to sharpfont 4 years ago (Robmaister/SharpFont#119) and has not been fixed so it is probably time to fork the repo and link a version of freetype without external dependencies. This will take me a little bit of time. If I am going to fork the repository, I an going to fix some other problems that I do not like as well.

See also:
https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170
for information about the MS VC runtime redistributable.

@DrJohnMelville
Copy link
Owner

So I think I got this fixed -- with a hack.

I created a new Nuget package, Melville.Sharpfont that packages msvcr120.dll into the nuget package. I believe that fixes this issue for windows 32 and windows 64.

I had a little problem that I am in the middle of an effort to make a bunch of work to make most of the library's members internal. I am halfway done with that. In order to make this available without breaking the version, I released a prerelease version 0.3.0-preview1 that incorporates the DLLs needed to fix this problem, but the internal/public status is an odd state. When I finish locking down and documenting the interface, I would like to release a 0.3 version with a lot of the public surface area removed, This is a big blocker to going to version 1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants