Azure app service unable to load libwkhtmltox. I work fine on the local machine, But upon deployment to azure, I got an error that cannot load or one of its dependencies. I search online and made some changes to my code, I got this error again.
I got the error below when I push to azure again
BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B) System.Runtime.InteropServices.NativeLibrary.LoadFromPath(string libraryName, bool throwOnError)
Below is the updated code
var wkHtmlToPdfFileDllName = "libwkhtmltox";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
wkHtmlToPdfFileDllName += ".so";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
wkHtmlToPdfFileDllName += ".dylib";
}
else
{
wkHtmlToPdfFileDllName += ".dll";
}
var wkHtmlToPdfPath = Path.Combine(Directory.GetCurrentDirectory(), "wkhtmltox", wkHtmlToPdfFileDllName);
CustomAssemblyLoadContext context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary(wkHtmlToPdfPath);
services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
I also added this to .csproj
<ItemGroup>
<None Remove="wkhtmltox\libwkhtmltox.dll" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="wkhtmltox\libwkhtmltox.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>