.net core app failing to load custom assembly, bad IL Format

0

I try to load the custom library in my app, and I get a Bad IL Format error. Here is my code:

var architectureFolder = (IntPtr.Size == 8) ? "64 bit" : "32 bit";
var wkHtmlToPdfPath = Path.Combine(_hostingEnvironment.ContentRootPath, $"wkhtmltox\\v0.12.4\\{architectureFolder}\\libwkhtmltox.dll");
AssemblyLoadContext context = new AssemblyLoadContext(GetType().Assembly.GetName().Name);
context.LoadFromAssemblyPath(wkHtmlToPdfPath);

Error details:

System.BadImageFormatException HResult=0x8007000B Message=Bad IL format. Source= StackTrace:

The library I try to load is libwkhtmltox. I am using this in my ASP.net zero boilerplate app, and in my Host project i can load the same asembly with:

var architectureFolder = (IntPtr.Size == 8) ? "64 bit" : "32 bit";
var wkHtmlToPdfPath = Path.Combine(_hostingEnvironment.ContentRootPath, $"wkhtmltox\\v0.12.4\\{architectureFolder}\\libwkhtmltox");
CustomAssemblyLoadContext context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary(wkHtmlToPdfPath);

How can I load the assembly in my public project?

c#
asp.net
asp.net-core
asked on Stack Overflow Dec 21, 2020 by sandi • edited Dec 21, 2020 by Useme Alehosaini

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0