如何修复 PowerShell 中的 DLL LoaderExceptions

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

我正在尝试加载itext7的

.dll
,但是如果我使用这个

Add-Type -Path "D:\Eigene\Packages\itext7.7.1.5\lib\net40\itext.kernel.dll"

我得到以下异常(翻译自德语):

Add-Type : Add-Type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
In Zeile:2 Zeichen:1
+ Add-Type -Path "D:\Eigene\Packages\itext7.7.1.5\lib\net40\itext.kerne ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Type], ReflectionTypeLoadException
    + FullyQualifiedErrorId : System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.AddTypeCommand

当我使用时:

try   { Add-Type -Path "D:\Eigene\Packages\itext7.7.1.5\lib\net40\itext.kernel.dll" }
catch { $_.Exception.LoaderExceptions }

它说(也是从德语翻译的):

文件或程序集“BouncyCastle.Crypto,版本=1.8.1.0, Culture=neutral, PublicKeyToken=0e99375e54769942" 或依赖项 没有找到。系统找不到指定的文件。

我该如何解决这个问题?

编辑: 我在我的系统上发现了一个 BouncyCastle dll,当我安装 itext7 软件包时它也会下载,但如果我在加载

"D:\Eigene\Packages\Portable.BouncyCastle.1.8.5\lib\net40\BouncyCastle.Crypto.dll"
之前加载
itext.kernel.dll
,它也不起作用。

powershell dll dllimport
1个回答
0
投票

您的程序集正在寻找与您不同的版本。 我不确定您是否可以在 powershell 中进行程序集绑定,就像使用应用程序一样,您可以将旧程序集绑定到新的示例: https://learn.microsoft.com/en-us/dotnet/framework/deployment/configuring-assemble-binding-redirection

您的错误是要求您使用以下公共令牌加载版本 1.8.1.0 的 dll:PublicKeyToken=0e99375e54769942

通常,程序集发布者不会更改其公共令牌,尽管在技术上,充气城堡可以做到这一点,因此您可能不需要指定这一点。

无论如何你需要找到旧版本(好像你有1.8.5)。这些可能是兼容的,但最好/最安全的选择是使用您正在加载所需的相同程序集。

如果您需要对较新的程序集进行绑定重定向,您可能会在这里找到一些帮助:Powershell - 在应用程序配置文件中找不到程序集绑定重定向

© www.soinside.com 2019 - 2024. All rights reserved.