3

我的系统上有这个 DataLink DLL - Interop.MSDASC.dll我正在尝试像这样从 Powershell 加载它 -

[Reflection.Assembly]::LoadFile("C:\Interop.MSDASC.dll") | out-null

但是,我收到以下错误 -

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

如何正确加载它?

4

3 回答 3

9

这是一个 32 位 COM 对象,因此您必须从 PowerShell 的 32 位实例加载它。要在 64 位版本的 Windows 上执行此操作,您可以在以下文件夹中执行 powershell.exe 或 powershell_ISE.exe:%SYSTEMROOT%\SysWow64\windowspowershell\v1.0

而且,这是完整的代码:

[Reflection.Assembly]::LoadFile("C:\Interop.MSDASC.dll") 
$dataLinkInstance = new-object MSDASC.DataLinksClass
$dataLinkInstance.WriteStringToStorage("C:\\FrmPowershell.udl", "Provider=SQLOLEDB.1;", 2)
于 2012-04-23T08:38:18.943 回答
3

我刚刚从http://datadictionary.codeplex.com/下载了它,并以与您使用相同的方式加载程序集,没有问题出现:

 [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

您可能在 x64 操作系统上吗?如果是,请在此处阅读http://datadictionary.codeplex.com/workitem/28807

于 2012-04-20T16:10:26.907 回答
-1
$comInterOp = "C\Temp\Interop.YourAssembly.dll"
[System.Reflection.Assembly]::LoadFile($comInterOp)
$yourClassObj = new-object YourAssembly.YourClassNameClass
$yourResult = $yourClassObj.YourMethod()
于 2020-03-10T04:45:07.867 回答