Target Platform and 'Could not load file or assembly' error

1

I have a Win Forms application that targets 64 bit platform (it is required as it uses the 64-bit Oracle.DataAccess libraries).

I've added an ASP.net forms application to this solution, and I would like to add a reference to the WinForms app to the ASP.net app.

My WebApp also targets 64 bit and builds correctly, but when I run it I get:

'Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies'.

I also made sure that the Oracle.DataAccess are the new 64-bit version. Any ideas?
The Winforms application (that has the reference to Oracle.DataAccess) are running 100%, so that tells me the problem might not be with the dll version.

More info on the error below:

=== Pre-bind state information ===
LOG: User = Domain\myUser
LOG: DisplayName = Oracle.DataAccess
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Oracle.DataAccess | Domain ID: 3
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:///D:/xx/UDWIntegration/UDWWeb/
LOG: Initial PrivatePath = D:\xx\UDWWeb\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\xx\UDWWeb\web.config
LOG: Using host configuration file: C:\Users\xx\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/xx/AppData/Local/Temp/Temporary ASP.NET Files/root/ef51aef3/7f23a77a/Oracle.DataAccess.DLL.
LOG: Attempting download of new URL file:///C:/Users/xx/AppData/Local/Temp/Temporary ASP.NET Files/root/ef51aef3/7f23a77a/Oracle.DataAccess/Oracle.DataAccess.DLL.
LOG: Attempting download of new URL file:///D:/xx/UDWWeb/bin/Oracle.DataAccess.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

Stack Trace: 


[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.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: 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.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
   System.Web.Compilation.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +124
   System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +44
   System.Web.Compilation.BuildManager.BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, Boolean ignoreErrors) +187
   System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +74
   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +299
   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +103
   System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) +165
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +43
   System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +31
   System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) +37
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +346
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
asp.net
winforms
assemblies
target-platform
asked on Stack Overflow Sep 9, 2013 by Cameron Castillo • edited Sep 16, 2013 by Cameron Castillo

3 Answers

7

Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config

Your trace clearly shows that your code is running in 32-bit mode. A 64-bit program loads the machine.config file from the c:\windows\microsoft.net\framework64 directory. So the BadImageFormatException is entirely expected.

It is not up to your project to configure in what mode it runs, it is the app-pool configuration in IIS that selects the bitness. Use the Advanced Settings as shown in this web page to configure it. Do make sure you talk to whomever normally configures the machine, this setting change is not an accident.

answered on Stack Overflow Sep 17, 2013 by Hans Passant
1

If you're having this issue while running/debugging a web app in Visual Studio (VS) using IIS Express make sure the following setting is checked:

Tools>Options>Projects & Solutions>Web Projects>Use the 64 bit version of IIS Express for web sites and projects

answered on Stack Overflow Feb 23, 2017 by joesmaname
0

This can be resolved by download and execute the install.bat file in 'ODAC112030Xcopy.zip' from 64-bit Oracle Data Access Components (ODAC) Downloads.

answered on Stack Overflow Sep 17, 2014 by Sunil

User contributions licensed under CC BY-SA 3.0