[英]System.DllNotFoundException: Unable to load DLL 'MvxSock.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
[英]System.DllNotFoundException: 'Unable to load DLL 'libwkhtmltox': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'
嘗試從 HTML 模板生成 PDF 時出錯。 我有一個不同的 class 庫來生成 PDF,我從另一個 controller 調用它。
System.DllNotFoundException:'無法加載 DLL'libwkhtmltox':找不到指定的模塊。 (來自 HRESULT 的異常:0x8007007E)'
您的 csproj 文件強制將 NuGet 程序集復制到構建的輸出:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
這些文件應該位於項目的根目錄下,並且您知道應該安裝 Microsoft Visual C++ Redistributable。 按照這個鏈接
如果您在 docker 中運行應用程序,請更新以安裝 .netcore 的 libwkhtmltox 依賴項
# Install libwkhtmltox dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
zlib1g \
fontconfig \
libfreetype6 \
libx11-6 \
libxext6 \
libxrender1 \
libjpeg62-turbo
從https://github.com/rdvojmoc/DinkToPdf/tree/master/v0.12.4下載包
通過自定義程序集引用將其添加到您的項目引用並在您的啟動項目中注冊。 這是自定義程序集加載上下文,可以從絕對路徑加載庫。
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(); } }
在 Statup.cs 中添加以下代碼。 在創建轉換器之前調用 CustomAssemblyLoadContext:
CustomAssemblyLoadContext context = new CustomAssemblyLoadContext(); context.LoadUnmanagedLibrary(path);
var converter = new SynchronizedConverter(new PdfTools()); services.AddSingleton(轉換器); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.