0

I am having one C# code which is working fine. I made PS script of same functionality which is not working.

$config = New-Object MyClass

Error it is throwing is

Type initializer for MyClass2 threw an exception.

Type initializer error is coming from other class(MyClass2) object which is strange.

I checked inner exception that says

Could not load file or assembly or one of its dependencies.

But all of assemblies are loaded.

P.S. - I made a console application in .net and tried to make MyClass object with all same assemblies which i used in PS script. In this application works perfectly fine.

P.S. - Same PS script is working in VS2015, if i make PS project and run script through VS2015.

diiN__________
  • 7,393
  • 6
  • 42
  • 69

1 Answers1

0

First, determine which assembly is missing, (for example using Dependency Walker, see this answer from SO). Then add the missing assembly using the Add-Type cmdlet:

Add-Type -Path "path_to_your_assembly"
Community
  • 1
  • 1
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
  • Actually I have loaded all the assemblies for safe side but still it is throwing same error. But same PS script is working in VS2015, so i guess its not related to any assembly. – RAHUL VERMA Jun 15 '16 at 09:55