【问题标题】:Target Platform and 'Could not load file or assembly' error目标平台和“无法加载文件或程序集”错误
【发布时间】:2013-09-13 02:09:57
【问题描述】:

我有一个针对 64 位平台的 Win Forms 应用程序(这是必需的,因为它使用 64 位 Oracle.DataAccess 库)。

我已向此解决方案添加了一个 ASP.net 表单应用程序,并且我想将 WinForms 应用程序的引用添加到 ASP.net 应用程序。

我的 WebApp 还针对 64 位并正确构建,但是当我运行它时,我得到:

'无法加载文件或程序集'Oracle.DataAccess'或其依赖项之一'。

我还确保 Oracle.DataAccess 是新的 64 位版本。 有什么想法吗?
Winforms 应用程序(具有对 Oracle.DataAccess 的引用)正在 100% 运行,因此这告诉我问题可能与 dll 版本无关。

有关以下错误的更多信息:

=== 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

【问题讨论】:

  • 您检查过 Oracle.DataAccess dll 上的引用吗?也许您的应用程序尝试从仅存在 x86 版本的另一个地方加载它。另外,当构建平台设置为 x64 时,请确认所有项目的项目属性 -> 构建 -> 平台目标为 x64。
  • 在两个应用程序的项目属性中检查目标框架并确保它们匹配。默认情况下,WinForms 将针对“.NET Framework 4 Client Profile”而不是“.NET Framework 4”
  • 我仔细检查了两个项目都在 x64 上。我重新下载了 Oracle.DataAccess 64 位 dll,并确保我引用了它。
  • 您是否在项目的 bin 文件夹中放置了 Oracle.DataAccess dll 的副本?那就是它试图从中加载它的地方。 Visual Studio 不会为您将引用位置的 dll 复制到 bin 文件夹。您必须手动完成。
  • 是的,我也这样做了 - 谢谢。

标签: asp.net winforms assemblies target-platform


【解决方案1】:

使用 C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config 中的机器配置文件

您的跟踪清楚地表明您的代码在 32 位模式下运行。 64 位程序从 c:\windows\microsoft.net\framework64 目录加载 machine.config 文件。所以 BadImageFormatException 完全是意料之中的。

不取决于你的项目来配置它运行的模式,它是 IIS 中的应用程序池配置来选择位数。使用this web page 中所示的高级设置进行配置。请确保您与通常配置机器的人交谈,此设置更改并非偶然。

【讨论】:

  • 谢谢 - 是否可以在设计期间更改我的开发机器上的此设置(即尚未部署在 IIS 上)?
  • 我也看到了那个,但它声明它没有经过全面测试的事实让我担心。我确实尝试过这个,但仍然没有成功。我还尝试在启用 32 位的 IIS 上进行部署,但仍然出现此错误。但是,我认为某些东西确实有效,因为错误消息看起来有点不同。因此,我将接受作为答案。谢谢。
【解决方案2】:

这可以通过从64-bit Oracle Data Access Components (ODAC) Downloads 下载并执行“ODAC112030Xcopy.zip”中的 install.bat 文件来解决。

【讨论】:

    【解决方案3】:

    如果您在使用 IIS Express 在 Visual Studio (VS) 中运行/调试 Web 应用时遇到此问题,请确保选中以下设置:

    Tools>Options>Projects & Solutions>Web Projects>为网站和项目使用 64 位版本的 IIS Express

    【讨论】:

      猜你喜欢
      • 2010-10-07
      • 2023-03-05
      • 1970-01-01
      • 2013-02-23
      • 2015-09-25
      • 2016-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多