“未能加载文件或程序集'System.Web.Mvc'或其某个依赖项。所定位的程序集清单定义与程序集引用不匹配(来自HRESULT的异常:0x80131040)”。
我检查了“System.Web.Mvc”的参考文献。在属性对话框中,运行时版本为“v4.0.30319”,版本为“5.0.0.0”。在web.config中,程序集设置如下:
<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>
完整的错误日志如下所示:
=== 预绑定状态信息 === 日志:显示名称 = System.Web.Mvc(部分) 警告:为程序集提供了部分绑定信息: 警告:程序集名称:System.Web.Mvc | 域 ID:2 警告:当仅提供程序集显示名称的一部分时会发生部分绑定。 警告:这可能导致绑定器加载错误的程序集。 警告:建议为程序集提供完全指定的文本标识, 警告:其中包括简单名称、版本、区域性和公钥令牌。 警告:有关此问题的更多信息和常见解决方案,请参见白皮书 http://go.microsoft.com/fwlink/?LinkId=109270 。 日志:应用程序基础目录 = file:///C:/Users/Ahmed/Documents/Visual Studio 2013/Projects/MediaSoft/Project/c#/YuClone/YuClone/ 日志:初始私有路径= C:\Users\Ahmed\Documents\Visual Studio 2013\Projects\MediaSoft\Project\c#\YuClone\YuClone\bin 调用程序集:(未知)。 === 日志:此绑定在默认加载上下文中开始。 日志:使用应用程序配置文件:C:\Users\Ahmed\Documents\Visual Studio 2013\Projects\MediaSoft\Project\c#\YuClone\YuClone\web.config 日志:使用主机配置文件:C:\Users\Ahmed\Documents\IISExpress\config\aspnet.config 日志:使用机器配置文件:C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config。 日志:此时未将策略应用于引用(私有、自定义、部分或基于位置的程序集绑定)。 日志:尝试下载新 URL file:///C:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET Files/root/22a49c5f/2f5ffeb9/System.Web.Mvc.DLL。 日志:尝试下载新 URL file:///C:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET Files/root/22a49c5f/2f5ffeb9/System.Web.Mvc/System.Web.Mvc.DLL。 日志:尝试下载新 URL file:///C:/Users/Ahmed/Documents/Visual Studio 2013/Projects/MediaSoft/Project/c#/YuClone/YuClone/bin/System.Web.Mvc.DLL。 日志:使用应用程序配置文件:C:\Users\Ahmed\Documents\Visual Studio 2013\Projects\MediaSoft\Project\c#\YuClone\YuClone\web.config 日志:使用主机配置文件:C:\Users\Ahmed\Documents\IISExpress\config\aspnet.config 日志:使用机器配置文件:C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config。 日志:在应用程序配置文件中找到重定向:5.0.0.0 重定向到 5.2.3.0。 日志:策略后引用:System.Web.Mvc,Version=5.2.3.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35 日志:尝试下载新 URL file:///C:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET Files/root/22a49c5f/2f5ffeb9/System.Web.Mvc.DLL。 日志:尝试下载新 URL file:///C:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET Files/root/22a49c5f/2f5ffeb9/System.Web.Mvc/System.Web.Mvc.DLL。 日志:尝试下载新 URL file:///C:/Users/Ahmed/Documents/Visual Studio 2013/Projects/MediaSoft/Project/c#/YuClone/YuClone/bin/System.Web.Mvc.DLL。 警告:比较程序集名称导致不匹配:次要版本 错误:无法完成程序集的设置(hr = 0x80131040)。 探测终止。以下是堆栈跟踪
[FileLoadException: 无法加载文件或程序集 'System.Web.Mvc' 或其其中一个依赖项。所定位的程序集清单定义与程序集引用不匹配。(HRESULT 异常:0x80131040)] [FileLoadException: 无法加载文件或程序集 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 或其其中一个依赖项。所定位的程序集清单定义与程序集引用不匹配。(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, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 或其其中一个依赖项。所定位的程序集清单定义与程序集引用不匹配。(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, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 或其其中一个依赖项。所定位的程序集清单定义与程序集引用不匹配。(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 的版本并指向正确的程序集?