DinkToPdf Net Core 无法加载 DLL 文件 [英] DinkToPdf Net Core not able to load DLL files
问题描述
我正在尝试使用 DinkToPdf 库从 HTML SQL 服务器数据库生成 PDF.
I am trying to generate PDFs from HTML SQL server database using DinkToPdf library.
在我添加的启动文件中:
In the startup file I have added:
var context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll"));
该行在启动网络应用程序时给了我这个错误:
The line gives me this error on launching the web app:
DllNotFoundException:无法加载 DLL 'C:Program FilesIIS Expresslibwkhtmltox.dll' 或其依赖项之一:找不到指定的模块.(来自 HRESULT 的异常:0x8007007E)
DllNotFoundException: Unable to load DLL 'C:Program FilesIIS Expresslibwkhtmltox.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
System.Runtime.Loader.AssemblyLoadContext.InternalLoadUnmanagedDllFromPath(string unmanagedDllPath)
System.Runtime.Loader.AssemblyLoadContext.InternalLoadUnmanagedDllFromPath(string unmanagedDllPath)
DllNotFoundException:无法加载 DLL 'C:Program FilesIIS Expresslibwkhtmltox.dll' 或其依赖项之一:找不到指定的模块.(来自 HRESULT 的异常:0x8007007E)
DllNotFoundException: Unable to load DLL 'C:Program FilesIIS Expresslibwkhtmltox.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
推荐答案
我找到了一些变通方法.它们并不完美但值得一试,它们确实提供了帮助,我能够从 SQL Server 生成 PDF.我将 .dll 文件放在以下文件夹中,它工作正常.
I found some work-arounds. They are not perfect but worth a try, and they did do help and I was able to generate PDFs from SQl Server. I put the .dll files in the following folder and it worked.
C:Program FilesIIS Express
C:Program FilesIIS Express
和加载的 .dll 文件
and the loaded the .dll files with
Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll");
我走整条路的另一种方式
The other way I went for the whole Path
context.LoadUnmanagedLibrary(Path.GetFullPath(@"C:UsersUsersource
eposWebSolutionWebApplibwkhtmltox.dll"));
他们都工作了.但是,我敦促 Net Core 开发人员在 GetCurrentDir 上工作得很好.或从项目或解决方案文件夹加载的方法
Both of them worked. However, I urge Net Core developers to work on the GetCurrentDir very well. Or a Method to load from the Project or Solution Folder
Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll");
这篇关于DinkToPdf Net Core 无法加载 DLL 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!