Monday, 26 August 2013

Could not load file or assembly

Could not load file or assembly

In my power shell script I am loading a custom assembly and then
instantiating a class of that assembly by New-Object.
Assembly.LoadFile() executes successfully but New-Object statement gives
the bellow exception.
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."
Script:
[System.Reflection.Assembly]::LoadFile("MyAssembly.dll")
$a=New-Object MyAssembly.MyClass -ArgumentList "arg1"
This custom assembly references only the following assemblies
System
System.Core
System.Runtime.Serialization
System.Xml.Linq
System.Data
System.Xml
I tried explicitly loading the System.Runtime.Serialization dll like
below. But same exception
[System.Reflection.Assembly]::Load("System.Runtime.Serialization,
Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
Any idea?

No comments:

Post a Comment