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

时间:2013-02-21 15:48:24

标签: asp.net-mvc oracle reference .net-assembly odp.net

背景

  • 我有一个包含Console项目和MVC4 Webapp的解决方案。
  • 参考Oracle.ManagedDataAccess(托管ODP.NET数据访问提供程序)。引用是指同一个文件。
  • 既不参考Oracle.ManagedDataAccess DTC。
  • 在VS Configuration Manager中,平台列为所有配置选项的“任何CPU”。
  • 两者的平台目标是“任何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.

我应该注意到,我知道这是32-和...之间的一个小问题。 64位版本的Oracle.ManagedDataAccess DLL。

但是,为什么针对相同DLL并使用相同设置编译的两个项目在工作方面会有不同的结果?

到目前为止,我已经尝试过......

  • 从IIS Express切换到Cassini只是为了踢...同样的问题
  • 试图以相同的方式使控制台应用程序失败......到目前为止它没有。

1 个答案:

答案 0 :(得分:8)

基于您的PrivatePath(C:\ Users \ killesj1 \ Repositories \ PEApps \ src \ app \ PEApps.Web \ bin)以及该私有路径中Oracle.ManagedDataAccessDTC.DLL的后续绑定尝试,您有一份ODP DTC组件在应用程序" bin"目录。虽然您不在此处显示,但输出的“堆栈跟踪”部分应显示对LoadAllAssembliesFromAppDomainBinDirectory的调用。该方法将尝试加载应用程序的所有.dll文件" bin"目录。在你的情况下,你在ODP DTC组件的位数和执行过程方面存在不匹配(你已经注意到你知道这类问题)。

您没有在控制台应用程序中看到此问题的原因是因为此类应用程序不会将LoadAllAssembliesFromAppDomainBinDirectory方法(或类似方法)调用到" preload"组件。

关于ODP DTC程序集如何进入应用程序的bin目录,也许你无意中包含了对它的引用并设置了#34; Copy Local" to" True"。或者您可能已将ODP DTC组件文件添加到项目中并设置"复制到输出目录" to" True"。也可以将文件手动复制到目录中。换句话说,文件如何在目录中结束有多种可能性。