我在 Visual Studio 的 Windows 窗体应用程序中使用 AForge 类没有问题。我现在正在尝试在 Windows PowerShell 中使用它们。

[Reflection.Assembly]::LoadFile('C:\Program Files\AForge.NET\IPLab\References\AForge.NET\AForge.Imaging.dll')

给出:
GAC    Version        Location
---    -------        --------
False  v2.0.50727     C:\Program Files\AForge.NET\IPLab\References\AForge.NET\AForge.Imaging.dll

即使 AForge.Imaging.dll 文件版本和产品版本都是 2.2.4.0,它仍显示 v2.0.50727。但是我没有问题执行以下实例化 AForge.Imaging.UnmanagedImage 对象 $umi (其中 $bmdata 是一个 Drawing.BitMapData 对象):
$umi = new-object Aforge.Imaging.UnmanagedImage $bmdata

但是当我尝试访问 $umi 对象时,例如 $umi.GetType(),我收到以下错误:
The following exception occurred while retrieving member "GetType": "Could not load file or assembly 'AForge, Version=2.2.4.0, Culture=neutral, PublicKeyToken=c1db6ff4eaa06aeb' or one of its dependencies. The system cannot find the file specified."
At line:1 char:13
+ $umi.GetType <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
    + FullyQualifiedErrorId : CatchFromBaseGetMember

可能有什么问题?谢谢。

最佳答案

“AForge.Imaging.dll”库依赖于以下必须加载的库;

Add-Type -AssemblyName "System.Drawing"
Add-Type -Path "E:\AForge.dll"
Add-Type -Path "E:\AForge.Math.dll"
Add-Type -Path "E:\AForge.Imaging.dll"

运行以下 PowerShell 命令以列出当前加载的程序集并验证您是否拥有必要的位。
[appdomain]::currentdomain.getassemblies() | sort -property fullname | format-table fullname

这是我的结果:
FullName
--------
AForge, Version=2.2.4.0, Culture=neutral, PublicKeyToken=c1db6ff4eaa06aeb
AForge.Imaging, Version=2.2.4.0, Culture=neutral, PublicKeyToken=ba8ddea9676ca48b
AForge.Math, Version=2.2.4.0, Culture=neutral, PublicKeyToken=abba2e25397ee8c9
Microsoft.PowerShell.Commands.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft.PowerShell.Commands.Management, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft.PowerShell.Commands.Utility, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft.PowerShell.ConsoleHost, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft.PowerShell.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft.WSMan.Management, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

我可以确认这对我有用。

10-08 09:39