.net 尝试加载 Oracle 客户端库引发 BadImageFormatException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15498391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Attempt to load Oracle client libraries threw BadImageFormatException
提问by Liza
While trying to connect to oracle database from .net getting the following exception:
尝试从 .net 连接到 oracle 数据库时出现以下异常:
Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
After going through many links i tried to overcome this exception by changing the platform target to Any CPU.Since it is wpf application,after changing the platform target it is throwing the following exception:
在浏览了许多链接后,我试图通过将平台目标更改为 Any CPU 来克服此异常。由于它是 wpf 应用程序,因此在更改平台目标后会引发以下异常:
'The invocation of the constructor on type 'SSC_GIP_UI.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.
'The invocation of the constructor on type 'SSC_GIP_UI.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.
But it runs fine with platform target x86 without throwing the above exception ,but it throws BadImageFormatException.
但是它在平台目标 x86 上运行良好而没有抛出上述异常,但是它抛出了BadImageFormatException。
The enironment on which i am working is:
Windows server 2008,
.net framework 4.0,
oracle 11g (64-bit)
我工作的环境是:Windows server 2008、
.net framework 4.0、oracle 11g (64-bit)
can anyone tell me.how to fix it?
谁能告诉我。如何解决它?
回答by GTG
This error indicates that you have a mismatch between 32 bits and 64 bits components in your application.
此错误表明您的应用程序中 32 位和 64 位组件不匹配。
When you run an application in 64 bits Windows, it may run as either 64 bits or 32 bits. If you have set the platform target as x86, it will run as 32 bits. If you have set your platform target as x64 or AnyCpu it will run as 64 bits.
当您在 64 位 Windows 中运行应用程序时,它可以作为 64 位或 32 位运行。如果您将平台目标设置为 x86,它将以 32 位运行。如果您将平台目标设置为 x64 或 AnyCpu,它将以 64 位运行。
Oracle has different versions of it's client, one is 32 bits and the other is 64 bits. So, if your application is running in 32 bits mode, you need to make sure your 32 bits Oracle client is installed.
Oracle 有不同版本的客户端,一个是 32 位,另一个是 64 位。因此,如果您的应用程序以 32 位模式运行,则需要确保安装了 32 位 Oracle 客户端。
回答by Njal
I think maybe you have to: Open IIS, find what application pool this application uses Go to that application pool, set a mark in 'Enable 32-bit applications'
我想也许你必须:打开 IIS,找到这个应用程序使用的应用程序池转到那个应用程序池,在“启用 32 位应用程序”中设置一个标记
回答by Ruben Steins
A completely alternative solution would be to use the Oracle Data Provider for .NETwhich will give you access to the Oracle.ManagedDataAccess dll that works regardless of whether you're on 32 or 64 bits. Read this article from Oracle Magazinefor a gentle introduction.
一个完全替代的解决方案是使用适用于 .NET的Oracle 数据提供程序,它可以让您访问 Oracle.ManagedDataAccess dll,无论您使用的是 32 位还是 64 位。阅读Oracle Magazine中的这篇文章,以进行简要介绍。
You can use it pretty much the same way as the System.Data.OracleClient although I'm not sure if there's feature parity between the two, so your mileage may vary.
您可以使用与 System.Data.OracleClient 几乎相同的方式使用它,尽管我不确定两者之间是否存在功能奇偶校验,因此您的里程可能会有所不同。

