oracle C# ODP.NET 加载文件或程序集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10658078/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:49:46  来源:igfitidea点击:

C# ODP.NET Load file or assembly

c#.netoracleodp.net

提问by Wjdavis5

I recently started testing on a C# (4.0) app that uses ODP.NET (Oracle.DataAccess 4.112.3)

我最近开始测试使用 ODP.NET (Oracle.DataAccess 4.112.3) 的 C# (4.0) 应用程序

I set this project to target any platform and publish the app.

我将此项目设置为针对任何平台并发布该应用程序。

When I run the program on the client machine I receive:

当我在客户端机器上运行程序时,我收到:

Could not load file or assembly 'Oracle.DataAccess, Version=4.112.3.0,Culture=neutral,
PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load 
a program with an incorrect format.

Like I said I've targeted 'Any CPU' and I've also embedded the Oracle.DataAccess assembly with the app.
I get this error on machines that have the Oracle client installed as well as machines that do not.

就像我说的,我的目标是“任何 CPU”,并且我还在应用程序中嵌入了 Oracle.DataAccess 程序集。
我在安装了 Oracle 客户端的机器上以及没有安装的机器上收到此错误。

Any help is appreciated.

任何帮助表示赞赏。

回答by Reed Copsey

Like I said I've targeted 'Any CPU'

就像我说的,我的目标是“任何 CPU”

This is likely the problem.

这很可能是问题所在。

The Oracle.DataAccess has separate versions for 32bitand 64bitsystems. If you are developing on a 32bit machine, and then deploying on a 64bit OS, you will receive this message.

Oracle.DataAccess 对于32 位64 位系统有不同的版本。如果您在 32 位机器上开发,然后在 64 位操作系统上部署,您将收到此消息。

You could easily work around this by building your application to target x86, and deploying the 32bit version of the data access components.

您可以通过构建面向 x86 的应用程序并部署 32 位版本的数据访问组件来轻松解决此问题。

回答by aquinas

As Reed Copsey said, there are two different DLLs. When you target ANYCpu, your app will run in 64 bit on a 64 bit machine, and 32 bit on a 32 bit machine. Therefore, if you want your app to work on 32 or 64 bit andrun in AnyCPU mode, you should change the reference of Oracle.DataAccess to Specific Version=false and copy local = false. When you deploy to a client, they shouldhave the oracle dll in the their GAC and it should pick up the correct version automagically.

正如 Reed Copsey 所说,有两种不同的 DLL。当您以 ANYCpu 为目标时,您的应用程序将在 64 位机器上以 64 位运行,在 32 位机器上以 32 位运行。因此,如果您希望您的应用程序在 32 位或 64 位上运行在 AnyCPU 模式下运行,您应该将 Oracle.DataAccess 的引用更改为特定版本 = false 并复制 local = false。当您部署到客户端时,他们的 GAC 中应该有 oracle dll,并且它应该自动选择正确的版本。

回答by Pushpesh Pandey

From debug Any cpu at top change the optin to debug X64, though internally Any CPu points to X64 only but that does not work, try to change it to x64 and it should work like a charm

从调试顶部的任何 cpu 更改 optin 以调试 X64,虽然在内部任何 CPU 仅指向 X64 但这不起作用,尝试将其更改为 x64,它应该像魅力一样工作

回答by Soundararajan

You should perhaps check if the Oracle.DataAccess assembly has any dependencies in your machine and that it is missing in the client machine.

您或许应该检查 Oracle.DataAccess 程序集在您的机器中是否有任何依赖项,以及它在客户端机器中是否缺失。