---
title: "【转】未能加载文件或程序集 XX 或它的某一个依赖项"
author: "三问飞絮"
date: "2014-07-24T13:59:09Z"
tags: []
categories: ["Web前端"]
slug: "xx"
draft: false
lastmod: "2014-07-24T13:59:09Z"
id: 2095957
url: "https://simon-fish.iteye.com/blog/2095957"
---

如果你将应用程序生成x86而不是Any CPU时，在64位操作系统中不会出错错误，而在32位操作系统中可能会出现以下错误:

# “/MyASP”应用程序中的服务器错误。

* * *

## *未能加载文件或程序集“MyASP”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新，无法加载此程序集。*

**说明:** 执行当前 Web 请求期间，出现未处理的异常。请检查堆栈跟踪信息，以了解有关该错误以及代码中导致错误的出处的详细信息。 

**异常详细信息:** System.BadImageFormatException: 未能加载文件或程序集“MyASP”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新，无法加载此程序集。

**源错误:** 

`执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。`

**程序集加载跟踪:** 下列信息有助于确定程序集“MyASP”无法加载的原因。

```
=== 预绑定状态信息 ===
日志: 用户 = RD-SIMON-291\Simon
日志: DisplayName = MyASP
 (Partial)
日志: Appbase = file:///D:/SharpDevelop Projects/MyASP/MyASP/
日志: 初始 PrivatePath = D:\SharpDevelop Projects\MyASP\MyASP\bin
调用程序集: (Unknown)。
===
日志: 此绑定从 default 加载上下文开始。
日志: 正在使用应用程序配置文件: D:\SharpDevelop Projects\MyASP\MyASP\web.config
日志: 使用 C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config 的计算机配置文件。
日志: 此时没有为引用应用策略(私有、自定义、分部或基于位置的程序集绑定)。
日志: 试图下载新的 URL file:///C:/Users/Administrator/AppData/Local/Temp/Temporary ASP.NET Files/myasp/be5834ef/4f369d9c/MyASP.DLL。
日志: 试图下载新的 URL file:///C:/Users/Administrator/AppData/Local/Temp/Temporary ASP.NET Files/myasp/be5834ef/4f369d9c/MyASP/MyASP.DLL。
日志: 试图下载新的 URL file:///D:/SharpDevelop Projects/MyASP/MyASP/bin/MyASP.DLL。
错误: 未能完成程序集的安装(hr = 0x8013101b)。探测终止。
```

**堆栈跟踪:** 

```
[BadImageFormatException: 未能加载文件或程序集“MyASP”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新，无法加载此程序集。]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +78
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +438
   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +305
   System.Reflection.Assembly.Load(String assemblyString) +50
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +116

[ConfigurationErrorsException: 未能加载文件或程序集“MyASP”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新，无法加载此程序集。]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +1026
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +339
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +85
   System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +54
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +230
   System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +131
   System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, String outputAssemblyName) +42
   System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +287
   System.Web.Compilation.BuildManager.CompileGlobalAsax() +50
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +482

[HttpException (0x80004005): 未能加载文件或程序集“MyASP”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新，无法加载此程序集。]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +90
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +607
   System.Web.Compilation.BuildManager.CallAppInitializeMethod() +45
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +971

[HttpException (0x80004005): 未能加载文件或程序集“MyASP”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新，无法加载此程序集。]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +765
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +138
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +361
```

 

* * *

**版本信息:** Microsoft .NET Framework 版本:2.0.50727.5456; ASP.NET 版本:2.0.50727.5477

 

 

 

 

**解决方法：**

**将应用程序生成为Any CPU就可以了**   
**反之，如果系统是64位的Win7，就应该将新项目的生成目标平台改为x86** 

**综上：**   
**64位的Win7 解决方案的生成目标平台设置为x86**   
**32位操作系统 解决方案的生成目标平台设置为AnyCPU** 

**另外一个网友的问题解决方法：** 

**我遇到过这个问题有两次，不过环境不同。** 

**第一次：Windows 2008 Server R2 64位；** 

**第二次：Windows 7 64位；** 

**原因分析：操作系统是64位的，但发布的程序引用了一些32位的ddl，所以出现了兼容性的问题。** 

**解决方案：IIS——应用程序池——高级设置——启用32位应用程序 ：true。**