无法加载文件或程序集“AutoMapper”或其某个依赖项。

9

当我部署时,遇到了这个问题,真的不知道该怎么解决。有什么想法吗?

Server Error in '/' Application.
Could not load file or assembly 'AutoMapper' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

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 'AutoMapper' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

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 'AutoMapper' could not be loaded.


=== Pre-bind state information ===
LOG: User = IIS APPPOOL\DefaultAppPool
LOG: DisplayName = AutoMapper
(Partial)
LOG: Appbase = file:///C:/inetpub/wwwroot/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\web.config
LOG: Using host configuration file:C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\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:/Windows/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/root/e22c2559/92c7e946/AutoMapper.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/root/e22c2559/92c7e946/AutoMapper/AutoMapper.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/bin/AutoMapper.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8013101b). Probing terminated.

Stack Trace: 


[BadImageFormatException: Could not load file or assembly 'AutoMapper' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.]
 System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
 System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416
  System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +166
  System.Reflection.Assembly.Load(String assemblyString) +35
  System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +190

 [ConfigurationErrorsException: Could not load file or assembly 'AutoMapper' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.]
 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11224200
     System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +388
 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +232
 System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +48
 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +210
 System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +76
 System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +283

System.Web.Compilation.BuildManager.CompileGlobalAsax() +50 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +676

这段代码是关于ASP.NET应用程序编译的。其中,BuildManager.CompileGlobalAsax()方法用于编译全局.asax文件,而BuildManager.EnsureTopLevelFilesCompiled()方法则用于确保应用程序中所有顶层文件都已编译。
 [HttpException (0x80004005): Could not load file or assembly 'AutoMapper' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.]
  System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +76
  System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +1012
  System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager,     IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +1025

 [HttpException (0x80004005): Could not load file or assembly 'AutoMapper' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.]
  System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11318198
  System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +88
  System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4348404

版本信息:Microsoft .NET Framework 版本:2.0.50727.5446;ASP.NET 版本:2.0.50727.5420

3个回答

11

应用程序池被配置为 .NET 2.0:

版本信息: Microsoft .NET Framework 版本:2.0.50727.5446; ASP.NET 版本:2.0.50727.5420

已部署的 AutoMapper 组件是为 .NET 4.0 构建的:

"此程序集是由一个比当前加载的运行时更新的运行时构建的,因此无法加载。"

这两者不能在一起工作。您可能可以通过将应用程序池切换到 .NET 4.0 来解决问题。


当我进入C:\inetpub\wwwroot\bin时,程序集就在那里。 - elranu
已更新答案。汇编代码已存在,但无法加载到旧版运行时中。 - driis
谢谢!我忘记设置我的应用程序池了! - elranu

2

尝试更改应用程序池... 在IIS中右键单击您的应用程序,管理应用程序=>高级设置=>更改池。 对我来说,asp.net v4池有效...


0

检查AutoMapper DLL的引用 - 可能是错误的。您可能需要将其删除并重新添加。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接