I have an SDK from a vendor, of which I am using a particular DLL which provides COM interop with the vendor system.
I have successfully created a POC C# project using classes in this DLL. I add the reference to the DLL, add the using clause for the namespace, voila. My target framework is 4.0 and platform is x86.
I now want to do use Powershell to achieve the same task, however I cannot get the DLL to load.
When I try
add-type -path $myDLL
or
[System.Reflection.Assembly]::LoadFrom($myDLL)
I get the following exception:
add-type : Could not load file or assembly 'file:///C:\Program Files
(x86)\Interwoven\WorkSite\IManage.dll' or one of its dependencies. The module was expected to contain
an assembly manifest.
At line:2 char:1
+ add-type -path $myDLL
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], BadImageFormatException
+ FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell.Commands.AddTypeComma
nd
I have confirmed I'm running in Powershell x86 and i even tried forcing CLRVersion to match the DLL ImageRuntimeVersion using the method described here with no success.
What else am I missing here? Thanks!
PS H:\> $env:processor_architecture
x86
PS H:\> $psversiontable
Name Value
---- -----
PSVersion 3.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34209
BuildVersion 6.2.9200.16398
PSCompatibleVersions {1.0, 2.0, 3.0}
PSRemotingProtocolVersion 2.2
$env:Processor_Architecturetells you the processor architecture not the process bitness. Of course, since it is x86, there is no possibility of running a 64-bit process by mistake. Use[Environment]::Is64BitProcessto tell if the current process is 64-bit.