Unable to load DLL 'libHarfBuzzSharp' error when using the Net Standard 2.0 version

Using GemBox PDF version 17.0.1342 via nuget package.
I have some GemBox PDF code in a class library, which works fine when the class library targets .NET framework 4.7.2 (and consequently using the .NET framework version of the GemBox PDF dlls).

I then created another version of that class library, but this time the class library targets .NET Standard 2.0. Everything builds fine, but when running the code, I get an exception like:

==
System.DllNotFoundException
HResult=0x80131524
Message=Unable to load DLL ‘libHarfBuzzSharp’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Source=HarfBuzzSharp
StackTrace:
at HarfBuzzSharp.HarfBuzzApi.hb_buffer_create()
at …ctor()
at .(Object , Boolean , Double )
at GemBox.Pdf.Content.PdfFormattedText.()
at GemBox.Pdf.Content.PdfFormattedText.()
at GemBox.Pdf.Content.PdfFormattedText.get_Width()

The image shows the dlls in the test application’s bin directory. I’ve crossed out (in red) assemblies used by my app which shouldn’t be relevant for this problem. The test app is a winforms application, targeting .Net framework.

I can see the dll HarfBuzzSharp.dll, but no libHarfBuzzSharp.dll.
Any ideas ?

(In case you are wondering why I can’t just use the .NET framework version of GemBox PDF dlls - I have to build the class library targeting .Net Standard 2.0, as the intent is in future it will be used by other applications that need it in .Net Standard 2.0. )

Adding additional info:

Here’s the code that this crashing, at line 51:

Hi,

You’ll need to target multiple frameworks with your library as well.
So, try using something like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net472;netstandard2.0</TargetFrameworks>
  </PropertyGroup>

  ...

</Project>

Does this solve your issue?

Regards,
Mario

Thanks Mario, I was actually trying to avoid using multi-targeting for this test, as I wanted to see the .Net Standard 2.0 version of the GemBox PDF assemblies working ok.

Without using multi-targeting, I did manage to get it to work, by referencing the packages: HarfBuzzSharp.NativeAssets.Win32 and SkiaSharp.NativeAssets.Win32 in the test application (exe). After building, I could then see the files: libHarfBuzzSharp.dll and libSkiaSharp.dll in the bin\Debug\x86 directory of the test app. After copying these files manually to the bin\Debug directory, the test app started working.

From performance point of view at runtime, would you expect any difference between using multi-targeting, vs using just the .NET standard version of the library ?

The problem is that your library has a NuGet dependency on GemBox.Pdf which has multiple targeted frameworks. So when you reference your library from your application the NuGet client will resolve the dependency of GemBox.Pdf based on the target of that application, not based on the target of your library.

And this is where that mismatch occurs, your library is using GemBox.Pdf for .NET Standard, but the NuGet client for your application project resolved the dependency to GemBox.Pdf for .NET Framework.

Anyway, note that you will be using just one of those at runtime, you’ll not be using both versions when having multiple targeting frameworks.

Regards,
Mario