Method invocation failed after compiling Powershell script in separate environment using PowerGUI script editor

22 Views Asked by At

I am encountering an issue after compiling a .ps1 file to .exe using the compile script tool using the PowerGUI Script Editor program.

Before compiling, when running in powershell, the script works as expected. Likewise it works after compiling with PowerGUI when targeting either .NET 3.5 or .NET 4.0. So I send it off to a colleague so they may digitally sign/compile it on their end, and when they provide me the final .exe I run into the following error:

Method invocation failed because [System.Collections.Generic.Dictionary`2+KeyCollection[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]] doesn't contain a method named 'Contains'.

I went through the original .ps1 file using the debugger to check all instances of dictionary objects in the script and piped them to get-member and found in each instance:

System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

I am thinking that somewhere in the process of sending it to a colleague and having them sign/compile it, the resulting .exe is now using Version=2.0.0.0 instead of Version=4.0.0.0., and I'm assuming that the earlier version of the dictionary does not have the 'Contains' method available to it for when it is called in the script.

I am wondering: what might be causing this switch in the version between when I compile it in my environment, vs. when it goes to my colleague's environment to digitally sign and compile using PowerGUI?

Thank you for any ideas.

0

There are 0 best solutions below