错误:无法加载文件或程序集“Oracle.ManagedDataAccessDTC”或其某个依赖项。

5

背景

  • 我有一个包含控制台项目和MVC4 Web应用程序的解决方案。
  • 两者都引用了Oracle.ManagedDataAccess(托管的ODP.NET数据访问提供程序)。引用是相同的文件。
  • 没有引用Oracle.ManagedDataAccess DTC。
  • 在VS配置管理器中,所有配置选项的平台都列为“Any CPU”。
  • 两个项目的平台目标都是“Any CPU”。

问题

控制台应用程序可以完美地执行。

当我尝试使用MVC4应用程序时,我看到:

Could not load file or assembly 'Oracle.ManagedDataAccessDTC' 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.ManagedDataAccessDTC' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Oracle.ManagedDataAccessDTC' could not be loaded.

    === Pre-bind state information ===
    LOG: User = [Redacted]\killesj1
    LOG: DisplayName = Oracle.ManagedDataAccessDTC
     (Partial)
    WRN: Partial binding information was supplied for an assembly:
    WRN: Assembly Name: Oracle.ManagedDataAccessDTC | Domain ID: 13
    WRN: A partial bind occurs when only part of the assembly display name is provided.
    WRN: This might result in the binder loading an incorrect assembly.
    WRN: It is recommended to provide a fully specified textual identity for the assembly,
    WRN: that consists of the simple name, version, culture, and public key token.
    WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
    LOG: Appbase = file:///C:/Users/killesj1/Repositories/PEApps/src/app/PEApps.Web/
    LOG: Initial PrivatePath = C:\Users\killesj1\Repositories\PEApps\src\app\PEApps.Web\bin
    Calling assembly : (Unknown).
    ===
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: C:\Users\killesj1\Repositories\PEApps\src\app\PEApps.Web\web.config
    LOG: Using host configuration file: C:\Users\killesj1\Documents\IISExpress\config\aspnet.config
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
    LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
    LOG: Attempting download of new URL file:///C:/Users/killesj1/AppData/Local/Temp/Temporary ASP.NET Files/root/e17fc384/1ed8df51/Oracle.ManagedDataAccessDTC.DLL.
    LOG: Attempting download of new URL file:///C:/Users/killesj1/AppData/Local/Temp/Temporary ASP.NET Files/root/e17fc384/1ed8df51/Oracle.ManagedDataAccessDTC/Oracle.ManagedDataAccessDTC.DLL.
    LOG: Attempting download of new URL file:///C:/Users/killesj1/Repositories/PEApps/src/app/PEApps.Web/bin/Oracle.ManagedDataAccessDTC.DLL.
    ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

我应该注意到,我知道这是Oracle.ManagedDataAccess DLL的32位和64位版本之间的问题。
然而,为什么针对同一DLL并使用相同设置编译的两个项目在工作方面会有不同的结果呢?
到目前为止,我尝试了以下方法: - 为了好玩,从IIS Express切换到Cassini...但是问题仍然存在。 - 尝试使控制台应用程序以同样的方式失败...但目前还没有成功。
1个回答

8
基于您的PrivatePath(C:\ Users \ killesj1 \ Repositories \ PEApps \ src \ app \ PEApps.Web \ bin)和在该私有路径中对Oracle.ManagedDataAccessDTC.DLL进行的绑定尝试,您在应用程序的“bin”目录中拥有ODP DTC程序集的副本。虽然您没有在此处显示它,但输出的堆栈跟踪部分应显示对LoadAllAssembliesFromAppDomainBinDirectory的调用。该方法将尝试加载应用程序“bin”目录中的所有.dll文件。在您的情况下,ODP DTC程序集与执行进程的位数不匹配(您已经注意到了这种问题)。
您在控制台应用程序中看不到此问题的原因是,此类应用程序不会调用LoadAllAssembliesFromAppDomainBinDirectory方法(或类似方法)来“预加载”程序集。
至于ODP DTC程序集如何进入应用程序的bin目录,也许您不小心包含了对它的引用,并将“Copy Local”设置为“True”。或者您可能将ODP DTC程序集文件添加到项目中,并将“Copy To Output Directory”设置为“True”。还有可能是手动将文件复制到目录中。换句话说,该文件以多种可能的方式出现在目录中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接