How to set native harfbuzz libraries (x86 or x64) for "Any CPU" option

I’ve discovered the situation when the same code works in main program block, but fails with the following error in UnitTests:

System.Exception: Text shaper factory failed to return text shaper for 'C:\WINDOWS\Fonts\calibrib.ttf', face index '0' ---> System.DllNotFoundException: Unable to load DLL 'harfbuzz': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

It seems like the issue based in wrong harfbuzz.dll version referred: it seems like Program copies 32-bit version into bin folder, while UnitTests copies 64-bit version.

Please find attached .net solution with demonstration the problem: HarfBuzz_error.zip (35.1 KB)

Also please note, it is another issue with this project. I think you’ll not able to compile it from attached sources, because mentioned harfbuzz.dll file will not be copied into bin folder. You need to reinstall HarfBuzz nuget. Or play with platform setting to forcing copy.

Or you can create your own solution in some simply steps:

  1. Create console project

  2. Create UnitTest project

  3. Add HarfBuzz nuget for both

  4. Check efficiency with the following sample code:

     var doc = new Document(@"..\..\..\input_Thai.docx");
     doc.LayoutOptions.TextShaperFactory = HarfBuzzTextShaperFactory.Instance;
     doc.Save(@"..\..\..\output_Thai.pdf", SaveFormat.Pdf);

@Vitaly_Filatenko

We have tested the scenario and have not found the shared issue. The Nuget package contains two sets of harfbuzz native libraries compiled for x86 and x64 platforms and special MSBuild script. Depending on project’s target platform the MSBuild script selects necessary native harfbuzz set of libraries (x86 or x64) and copies them to TargetDir of the project.

This MSBuild script detects project’s target platform using {PlatformTarget} and {Prefer32Bit} parameters of the project. It is mostly works fine for all types of projects except ASP.NET WebForms.

1 Like

Thank you. Today I’ve discovered special settings for preferred processor architecture on testing:

изображение.png (15.4 KB)

@Vitaly_Filatenko

Thanks for your feedback. Have your problem solved? Please let us know, we will then close this thread.

Yes, the option mentioned above and using .runsetings file with specifying preferred processor architecture helped me to resolve the issue completely.