We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Unable to load library 'harfbuzz.dll'

I tried to convert DocX file which contains Bengali fonts, Opentype features [1] needs to be enabled for that. I’m using following code in ASP.NET MVC to convert docx, which throws an exception that Unable to load 'harfbuzz.dll’

string filePath = Server.MapPath("/Files/combineFonts.docx");

// Load a Word file from the local drive.
var doc = new Document(filePath);

doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;

doc.Save(filePath + ".pdf");

But the library works fine for Console and ASP.NET Core Application. Will you please help me regarding this issue.

Docx File: combineFonts.docx (15.1 KB)

Project Link: https://github.com/maaaruf/WordConverter/


@maaaruf It looks like native harfbuzz.dll is not deployed properly in this type of application. If load the dll manually everything works fine:

// I put the Aspose.Words.Shaping.HarfBuzz package into /files folder
doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
public static class HarfBuzzHelper
	[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
	private static extern IntPtr LoadLibrary(string libname);

	public static void LoadNativeLibrary(string root)
        var harfBuzzPath = Path.Combine(root, "Aspose.Words.Shaping.HarfBuzz.22.5.0\\runtimes", 
            (IntPtr.Size == 4 ? "win-x86" : "win-x64"), "native\\harfbuzz.dll");
        // for .net core
        // var lib = System.Runtime.InteropServices.NativeLibrary.Load(harfBuzzPath);
        // for .net framework
        var lib = LoadLibrary(harfBuzzPath);

I will also consult with the developer responsible for Aspose.Words.Shaping.HarfBuzz package and try to find the reason of this problem. But I suspect this is no Aspose.Words, but MVC publisher problem.

@maaaruf This is a known issue. Nuget package contains two native harfbuzz.dll compiled for x86 and x64 platforms and special MSBuild script.
Depending on project’s target platform, the MSBuild script chooses necessary native harfbuzz.dll (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 OK for all types of projects except ASP.NET WebForms.
Project’s target platform may depend on {Use64BitIISExpress} parameter of the project.
In general, there is no good way to detect actual project’s target platform if {Use64BitIISExpress} set to “Default” and {PlatformTarget} set to “Any CPU”.

The workaround: Please try to set explicit value in {Use64BitIISExpress} = x86 or x64. And REBUILD the project.

The issues you have found earlier (filed as WORDSNET-21399) have been fixed in this Aspose.Words for .NET 23.2 update also available on NuGet.