DinkToPdf Net Core无法加载DLL文件

问题描述 投票:0回答:2

我尝试使用DinkToPdf库从html sql server数据库生成PDF。

在我添加的启动文件中

var context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll"));

该行在启动Web应用程序时给出了错误

DllNotFoundException:无法加载DLL'C:\ Program Files \ IIS Express \ libwkhtmltox.dll'或其依赖项之一:找不到指定的模块。 (来自HRESULT的异常:0x8007007E)

System.Runtime.Loader.AssemblyLoadContext.InternalLoadUnmanagedDllFromPath(string unmanagedDllPath)

DllNotFoundException:无法加载DLL'C:\ Program Files \ IIS Express \ libwkhtmltox.dll'或其依赖项之一:找不到指定的模块。 (来自HRESULT的异常:0x8007007E)

尽可能随时为您提供帮助

c# .net-core wkhtmltopdf html-to-pdf dinktopdf
2个回答
1
投票

为了防止其他人遇到同样的问题,我可以通过安装Microsoft Visual C ++ 2015 Redistributable来解决它。


0
投票

我发现了一些解决方法。它们并不完美但值得一试,它们确实提供了帮助,我能够从SQl Server生成PDF。我把.dll文件放在以下文件夹中,它工作正常。

C:\ Program Files \ IIS Express

并加载.dll文件

Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll");

另一种方式我去了整个路径

context.LoadUnmanagedLibrary(Path.GetFullPath(@"C:\Users\User\source\repos\WebSolution\WebApp\libwkhtmltox.dll"));

他们俩都工作了。但是,我敦促Net Core开发人员很好地处理GetCurrentDir。或者从项目或解决方案文件夹加载的方法

Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll");
© www.soinside.com 2019 - 2024. All rights reserved.