【发布时间】:2019-10-24 22:01:14
【问题描述】:
我正在使用 DinkToPDF 库将 html 字符串转换为等效的 PDF。 要使用这个库,我们必须导入提供的本地库 libwkhtmltox.dll。当我在本地运行我的 .net 核心项目时,这工作正常,但是当我尝试在 Azure 中将我的 Web 项目作为应用服务发布时,我收到以下错误,
未处理的异常:System.DllNotFoundException:无法加载共享库“/home/site/wwwroot/libwkhtmltox.dll”或其依赖项之一。为了帮助诊断加载问题,考虑设置 LD_DEBUG 环境变量:/home/site/wwwroot/libwkhtmltox.dll: cannot open shared object file: No such file or directory
我在下面的 startup.cs 文件中引用了库的使用情况。
internal class CustomAssemblyLoadContext : AssemblyLoadContext
{
public IntPtr LoadUnmanagedLibrary(string absolutePath)
{
return LoadUnmanagedDll(absolutePath);
}
protected override IntPtr LoadUnmanagedDll(String unmanagedDllName)
{
return LoadUnmanagedDllFromPath(unmanagedDllName);
}
protected override Assembly Load(AssemblyName assemblyName)
{
throw new NotImplementedException();
}
}
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
var context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll"));
.
.
.
}
请帮我找出这个错误的解决方案。
【问题讨论】:
-
你如何解决这个问题?可以更新吗?