小编ama*_*ion的帖子

如何将 .NET 程序集正确添加到 Powershell 会话?

我有一个 .NET 程序集(一个 dll),它是我们在这里使用的备份软件的 API。它包含一些我想在我的 Powershell 脚本中利用的属性和方法。但是,我遇到了很多问题,首先加载程序集,然后在加载程序集后使用任何类型。

完整的文件路径是:

C:\rnd\CloudBerry.Backup.API.dll
Run Code Online (Sandbox Code Playgroud)

在 Powershell 中,我使用:

$dllpath = "C:\rnd\CloudBerry.Backup.API.dll"
Add-Type -Path $dllpath
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Add-Type : Unable to load one or more of the requested types. Retrieve the
LoaderExceptions property for more information.
At line:1 char:9
+ Add-Type <<<<  -Path $dllpath
+ CategoryInfo          : NotSpecified: (:) [Add-Type], ReflectionTypeLoadException
+ FullyQualifiedErrorId : System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.AddTypeComma
ndAdd-Type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Run Code Online (Sandbox Code Playgroud)

在另一个 .NET 程序集DotNetZip …

powershell .net

30
推荐指数
2
解决办法
9万
查看次数

标签 统计

.net ×1

powershell ×1