Error: Could not load file or assembly 'Oracle.ManagedDataAccessDTC' or one of its dependencies

江枫思渺然 提交于 2019-12-23 10:54:43

问题


Background

  • I have a solution containing a Console project and an MVC4 Webapp.
  • Both Reference Oracle.ManagedDataAccess (the managed ODP.NET data access provider). The reference is to the same file.
  • Neither reference Oracle.ManagedDataAccess DTC.
  • In VS Configuration Manager, the platform is listed as "Any CPU" for all configuration options.
  • The platform target for both is "Any CPU"

Problem

The console application executes perfectly fine.

When I try to use the MVC4 application, I see:

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.

I should note that I'm aware this is a bitness issue between 32- & 64-bit editions of the Oracle.ManagedDataAccess DLL.

However, why would two projects targeting the same DLL and compiled with the same settings have different results in terms of working?

So far, I've tried...

  • Switching from IIS Express to Cassini just for kicks...same issue
  • Tried to make the Console application fail in the same way...so far it doesn't.

回答1:


Based on your PrivatePath (C:\Users\killesj1\Repositories\PEApps\src\app\PEApps.Web\bin) and the subsequent bind attempt for Oracle.ManagedDataAccessDTC.DLL in that private path, you have a copy of the ODP DTC assembly in the application's "bin" directory. Though you don't show it here, the Stack Trace section of the output should show a call to LoadAllAssembliesFromAppDomainBinDirectory. That method will attempt to load all .dll files in the application's "bin" directory. In your case you have a mismatch with respect to bitness of the ODP DTC assembly and the executing process (you've noted you are aware of this sort of issue).

The reason you do not see this issue with a console application is because such an application will not call the LoadAllAssembliesFromAppDomainBinDirectory method (or similar) to "preload" assemblies.

As to how the ODP DTC assembly got into the application's bin directory, perhaps you inadvertently included a reference to it and set "Copy Local" to "True". Or perhaps you added the ODP DTC assembly file to the project and set "Copy To Output Directory" to "True". It's also possible that the file was manually copied into the directory. In other words, there are multiple possibilities as to how the file ended up in the directory.



来源:https://stackoverflow.com/questions/15006449/error-could-not-load-file-or-assembly-oracle-manageddataaccessdtc-or-one-of-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!