加载Oracle.DataAccess.dll时出错

时间:2015-08-10 10:41:35

标签: oracle powershell powershell-v2.0 odp.net

我在powershell中执行以下命令时遇到错误。

[Reflection.Assembly]::LoadFile("C:\Oracle\Oracle11gClientR1\ODP.NET\bin\2.x\Oracle.DataAccess.dll")

这是错误。

Exception calling "LoadFile" with "1" argument(s): " is not a valid Win32 application. (Exception from HRESULT: 0x80070
0C1)"
At line:1 char:32
+ [Reflection.Assembly]::LoadFile <<<< ("C:\Oracle\Oracle11gClientR1\ODP.NET\bin\2.x\Oracle.DataAccess.dll")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

有人可以告诉我我做错了什么吗?

我检查了这条路(

  

C:\甲骨文\ Oracle11gClientR1 \ ODP.NET \ BIN \ 2.x的\ Oracle.DataAccess.dll

)这是正确的。

更新 Powershell版本是2。

我也试过这些

Add-Type -AssemblyName "c:\Oracle\Oracle11gClientR1\ODP.NET\bin\2.x\Oracle.DataAccess.dll"

Add-Type "c:\Oracle\Oracle11gClientR1\ODP.NET\bin\2.x\Oracle.DataAccess.dll"

但没有运气。

1 个答案:

答案 0 :(得分:2)

在这种情况下,您很可能正在使用PowerShell version 2.0 .NET Framework version 4.0 不兼容。尝试使用兼容的.NET Framework版本。检查

Powershell版本运行命令

$PSVersionTable.psversion

要检查安装的.NET框架版本,请运行以下命令并检查第二行第3列数据

gci "hklm:\SOFTWARE\Microsoft\NET Framework Setup\NDP"

修改

更多建议:

尝试使用LoadFrom()代替

[Reflection.Assembly]::Assembly.LoadFrom("c:\Oracle\Oracle11gClientR1\ODP.NET\bin\2.x\Oracle.DataAccess.dll");

(或)尝试使用Add-Type代替

Add-Type -AssemblyName "c:\Oracle\Oracle11gClientR1\ODP.NET\bin\2.x\Oracle.DataAccess.dll" 

此外,请确保您没有尝试从64位Windows Oracle.DataAccess.dll加载32位Powershell。我的意思是他们俩都应该是有利可图的。