I have this DataLink DLL on my system - Interop.MSDASC.dll I am trying to load the same from Powershell like this -
[Reflection.Assembly]::LoadFile("C:\Interop.MSDASC.dll") | out-null
But, I get the following error -
Exception calling "LoadFile" with "1" argument(s): "Could not load file or assembly 'Interop.MSDASC.dll' or one of its dependencies. is not a
valid Win32 application. (Exception from HRESULT: 0x800700C1)"
At line:1 char:32
+ [Reflection.Assembly]::LoadFile <<<< ("C:\Interop.MSDASC.dll") | out-null
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
How do I correctly load this ?
This is a 32 bit COM object and therefore you must load it from a 32 bit instance of PowerShell. To do this on a 64 bit version of Windows you can execute powershell.exe or powershell_ISE.exe in this folder: %SYSTEMROOT%\SysWow64\windowspowershell\v1.0
And, this is the complete code:
[Reflection.Assembly]::LoadFile("C:\Interop.MSDASC.dll")
$dataLinkInstance = new-object MSDASC.DataLinksClass
$dataLinkInstance.WriteStringToStorage("C:\\FrmPowershell.udl", "Provider=SQLOLEDB.1;", 2)
I've just downloaded it from http://datadictionary.codeplex.com/ and load assembly in the same way you use and no issue come:
[System.Reflection.Assembly]::LoadFile( "c:\Program Files\DataDictionaryCreator\Interop.MSDASC.dll")
GAC Version Location
--- ------- --------
False v2.0.50727 c:\Program Files\DataDictionaryCreator\Interop.MSDASC.dll
Are you maybe on a x64 operative system? if yes read here http://datadictionary.codeplex.com/workitem/28807
$comInterOp = "C\Temp\Interop.YourAssembly.dll"
[System.Reflection.Assembly]::LoadFile($comInterOp)
$yourClassObj = new-object YourAssembly.YourClassNameClass
$yourResult = $yourClassObj.YourMethod()
User contributions licensed under CC BY-SA 3.0