在 IIS 64 位服务器上部署时出现 'Oracle.DataAccess' 缺少依赖项错误

Getting missing dependency error for 'Oracle.DataAccess' when deploying on IIS 64 Bit Server

我是 .Net 的新手。我创建了一个连接到数据库并执行一些事务的代码。对于数据访问管理器,我在本地添加了引用 Oracle.DataAccess.86 (Oracle.DataAccess.dll) 和 运行 以及 "Any CPU"。它工作正常。但是当我将它部署在具有 64 位 IIS 运行 的服务器上时,它会给我以下错误:

Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.

[BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +225 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +110 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22 System.Reflection.Assembly.Load(String assemblyString) +34 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48

如何找到解决此错误的方法?

如果IIS是64位的,那么你还需要Oracle.DataAccess.dll的64位版本。我假设 Oracle.DataAccess 根本没有安装在您的服务器上,请验证安装是否正确。请注意,Oracle.DataAccess.dll 需要一个 Oracle 客户端(通常是 Oracle 实例客户端),这也必须与 Oracle.DataAccess.dll.

的体系结构相同

对Oracle.DataAccess.dll的引用是一样的。该应用程序(在您的情况下为 IIS)将自动加载正确的程序集 - 前提是它已安装并在机器上可用。您可以删除项目文件中的 processorArchitecture=x86 属性,您可以编辑 *.csproj,resp。 *.vbproj 使用文本编辑器手动归档。

您的问题是将错误的 Oracle DLL 加载到内存中

如果您将程序集构建到 AnyCPU...

要求 运行 作为 x64 - 安装了 Oracle 客户端 x64,Oracle.DataAccess.dll 部署了 x64,AppPool 设置 "run 32 bit" = false

要求 运行 作为 x86 - 安装了 Oracle 客户端 x86,Oracle.DataAccess.dll 部署了 x86,设置了 AppPool "run 32 bit" = true

但是 你为什么要在 2019 年使用 Oracle.DataAccess.dll?使用 Oracle.ManagedDataAccess.dll。安装一小组连接组件 (ODAC),不需要 Oracle 客户端,x64/x86 - 所有这些都将作为 AnyCPU 完成。更好的是,为 Visual Studio 安装 Oracle 开发工具,其中将包括 ODAC