在我的 power shell 脚本中,我正在加载一个自定义程序集,然后通过New-Object
.
Assembly.LoadFile()
执行成功,但New-Object
语句给出了以下异常。
New-Object : Exception calling ".ctor" with "1" argument(s): "Could not load file or assembly 'MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of i
ts dependencies. The system cannot find the file specified."
脚本:
[System.Reflection.Assembly]::LoadFile("MyAssembly.dll")
$a=New-Object MyAssembly.MyClass -ArgumentList "arg1"
此自定义程序集仅引用以下程序集
System
System.Core
System.Runtime.Serialization
System.Xml.Linq
System.Data
System.Xml
我尝试显式加载 System.Runtime.Serialization dll,如下所示。但同样的例外
[System.Reflection.Assembly]::Load("System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
任何的想法?