本文介绍了无法加载文件或程序集“System.Web.Mvc".如何使用正确的参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 ASP.NET Web 表单构建的应用程序,它也支持 MVC 5.我在我的项目中包含了 MVC 5 API 控制器,为此我不得不将 Json 从 4.5 版升级到 7.0 版.在启动应用程序时进行这些更改后,我收到以下错误:

I have an application built on ASP.NET web forms which also supports MVC 5. I included MVC 5 API controllers in my project for which I had to upgrade Json from version 4.5 to 7.0. After making those changes when I launched the application, I get the following error:

无法加载文件或程序集System.Web.Mvc"或其之一依赖关系.定位的程序集的清单定义没有匹配程序集引用.(来自 HRESULT 的异常:0x80131040)

我检查了 System.Web.Mvc 的参考.在属性对话框中,运行时版本为 v4.0.30319,版本为 5.0.0.0.在 web.config 中,程序集设置如下:

I checked the reference for System.Web.Mvc. In the property dialog run time version is v4.0.30319 and version is 5.0.0.0. In web.config, the assemblies are set as the following:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="AntiXssLibrary" publicKeyToken="d127efab8a9c114f" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </dependentAssembly>
  <!--<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
  </dependentAssembly>-->
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </dependentAssembly>
</assemblyBinding>

完整的错误日志如下所示:

The full error log is shown below:

=== 预绑定状态信息 === LOG: DisplayName = System.Web.Mvc (Partial) WRN: 部分绑定信息被提供给一个程序集:警告:程序集名称:System.Web.Mvc |域 ID:2 警告:A部分绑定发生在只有部分程序集显示名称是假如.警告:这可能会导致活页夹加载不正确的部件.警告:建议提供完全指定的文本程序集的标识,警告:由简单名称组成,版本、文化和公钥令牌.警告:请参阅白皮书http://go.microsoft.com/fwlink/?LinkId=109270 了解更多信息和此问题的常见解决方案.日志:Appbase =file:///C:/Users/Ahmed/Documents/Visual Studio2013/Projects/MediaSoft/Project/c#/YuClone/YuClone/日志:初始PrivatePath = C:UsersAhmedDocumentsVisual Studio2013ProjectsMediaSoftProjectc#YuCloneYuClonein 调用程序集:(未知).=== LOG:此绑定在默认加载上下文中启动.日志:使用应用程序配置文件:C:UsersAhmedDocumentsVisual Studio2013ProjectsMediaSoftProjectc#YuCloneYuCloneweb.config 日志:使用主机配置文件:C:UsersAhmedDocumentsIISExpressconfigaspnet.config 日志:使用机器配置文件来自C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config.日志:此时未将策略应用于参考(私人,自定义、部分或基于位置的程序集绑定).日志:尝试下载新网址file:///C:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET文件/root/22a49c5f/2f5ffeb9/System.Web.Mvc.DLL.日志:尝试下载新网址file:///C:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET文件/root/22a49c5f/2f5ffeb9/System.Web.Mvc/System.Web.Mvc.DLL.日志:正在尝试下载新的 URL 文件:///C:/Users/Ahmed/Documents/Visual工作室2013/Projects/MediaSoft/Project/c#/YuClone/YuClone/bin/System.Web.Mvc.DLL.LOG:使用应用程序配置文件:C:用户艾哈迈德文档Visual Studio2013ProjectsMediaSoftProjectc#YuCloneYuCloneweb.config 日志:使用主机配置文件:C:UsersAhmedDocumentsIISExpressconfigaspnet.config 日志:使用机器配置文件来自C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config.日志:在应用程序配置文件中找到重定向:5.0.0.0重定向到 5.2.3.0.LOG:后政策参考:System.Web.Mvc,版本=5.2.3.0,文化=中性,PublicKeyToken=31bf3856ad364e35 日志:正在尝试下载新 URLfile:///C:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET文件/root/22a49c5f/2f5ffeb9/System.Web.Mvc.DLL.日志:尝试下载新网址file:///C:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET文件/root/22a49c5f/2f5ffeb9/System.Web.Mvc/System.Web.Mvc.DLL.日志:正在尝试下载新的 URL 文件:///C:/Users/Ahmed/Documents/Visual工作室2013/Projects/MediaSoft/Project/c#/YuClone/YuClone/bin/System.Web.Mvc.DLL.警告:比较程序集名称导致不匹配:次要版本错误:未能完成程序集的设置(hr = 0x80131040).探测终止.

以下是堆栈跟踪

[FileLoadException: 无法加载文件或程序集System.Web.Mvc"或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT 的例外:0x80131040)]

[FileLoadException: 无法加载文件或程序集 'System.Web.Mvc,版本=5.2.3.0,文化=中性,PublicKeyToken=31bf3856ad364e35' 或它的依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT 的例外:0x80131040)] System.Reflection.RuntimeAssembly._nLoad(AssemblyName文件名、字符串代码库、证据程序集安全性、运行时程序集locationHint、StackCrawlMark&stackMark,IntPtr pPrivHostBinder,布尔值 throwOnFileNotFound、布尔值用于内省、布尔值抑制安全检查)+0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName 文件名,字符串代码库,证据程序集安全性,运行时程序集位置提示,StackCrawlMark&stackMark、IntPtr pPrivHostBinder、布尔值throwOnFileNotFound,内省的布尔值,布尔值抑制安全检查)+36
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyNameassemblyRef, 证据 assemblySecurity, RuntimeAssembly reqAssembly,StackCrawlMark&stackMark、IntPtr pPrivHostBinder、布尔值throwOnFileNotFound,内省的布尔值,布尔值抑制安全检查)+152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,证据组装安全,StackCrawlMark&堆栈标记,IntPtrpPrivHostBinder,内省的布尔值)+77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,证据组装安全,StackCrawlMark&堆栈标记,布尔值forIntrospection) +21 System.Reflection.Assembly.Load(StringassemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串程序集名称,布尔型 starDirective) +38

[FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)] 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) +36
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) +21 System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: 无法加载文件或程序集'System.Web.Mvc,版本=5.2.3.0,文化=中性,PublicKeyToken=31bf3856ad364e35' 或其依赖项之一.这定位的程序集的清单定义与程序集不匹配参考.(来自 HRESULT 的异常:0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串程序集名称,布尔型 starDirective) +738
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()+217 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfoai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSectioncompConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()+92 System.Web.Compilation.BuildManager.CallPreStartInitMethods(StringpreStartInitListPath, Boolean&isRefAssemblyLoaded) +290
System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManagerappManager、IApplicationHost appHost、IConfigMapPathFactoryconfigMapPathFactory、HostingEnvironmentParameters、hostingParameters、PolicyLevel policyLevel,异常 appDomainCreationException) +531

[ConfigurationErrorsException: Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +738
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +217 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +92 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +290
System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531

[HttpException (0x80004005): 无法加载文件或程序集'System.Web.Mvc,版本=5.2.3.0,文化=中性,PublicKeyToken=31bf3856ad364e35' 或其依赖项之一.这定位的程序集的清单定义与程序集不匹配参考.(来自 HRESULT 的异常:0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9924184System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext 上下文)+101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequestwr,HttpContext 上下文)+261

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9924184 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261

如何升级 System.Web.Mvc 的版本以指向正确的程序集?

How do I upgrade the version of System.Web.Mvc to point to the correct assembly?

推荐答案

错误是由于绑定不正确造成的.我改变了:

Error was caused due to incorrect binding. I changed:

<dependentAssembly>
    <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </dependentAssembly>

  <dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.0.0.0" />

现在可以使用了.

这篇关于无法加载文件或程序集“System.Web.Mvc".如何使用正确的参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 07:33
查看更多