我经历过很多回答,但我没有找到解决问题的方法.这无法加载文件或程序集'System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'以及我使用过的许多其他文件或程序集.
****这是运行时错误:****
无法加载文件或程序集'System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)
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.
Run Code Online (Sandbox Code Playgroud)
异常详细信息:System.IO.FileLoadException:无法加载文件或程序集'System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)
来源错误:
在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.
程序集加载跟踪:以下信息有助于确定无法加载程序集"System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35"的原因.
===预绑定状态信息===日志:DisplayName = System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35(完全指定)LOG:Appbase = file:/// C:/ menupoly/abdulla/men1/MenuSnaps/LOG:Initial PrivatePath = C:\ menupoly\abdulla\men1\MenuSnaps\bin
日志:此绑定在默认加载上下文中启动.日志:使用应用程序配置文件:C:\ menupoly\abdulla\men1\MenuSnaps\web.config日志:使用主机配置文件:C:\ Users\user\Documents\IISExpress\config\aspnet.config日志:使用机器配置文件来自C:\ Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.日志:后策略引用:System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35日志:尝试下载新的URL文件:/// C:/ Users/user/AppData/Local/Temp/Temporary ASP.NET Files/root/c0c49273/dff4168/System.Web.WebPages.Razor.DLL.日志:尝试下载新的URL文件:/// C:/ Users/user/AppData/Local/Temp/Temporary ASP.NET Files/root/c0c49273/dff4168/System.Web.WebPages.Razor/System.Web.WebPages .Razor.DLL.日志:尝试下载新的URL文件:/// C:/menupoly/abdulla/men1/MenuSnaps/bin/System.Web.WebPages.Razor.DLL.警告:比较程序集名称导致不匹配:主要版本错误:无法完成程序集的设置(hr = 0x80131040).探测终止.
堆栈跟踪:
[FileLoadException:无法加载文件或程序集'System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(来自HRESULT的异常:0x80131040)] Microsoft.Web.Helpers.PreApplicationStartCode.Start()+ 0
[InvalidOperationException:预应用程序启动初始化方法启动类型Microsoft.Web.Helpers.PreApplicationStartCode引发异常,并显示以下错误消息:无法加载文件或程序集'System.Web.WebPages.Razor,Version = 3.0.0.0, Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其中一个依赖项.定位的程序集的清单定义与程序集引用不匹配.(来自HRESULT的异常:0x80131040).] System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection 1 methods, Func1 setHostingEnvironmentCultures)+613 System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods)+141 System.Web.Compilation.BuildManager. CallPreStartInitMethods(String preStartInitListPath,Boolean&isRefAssemblyLoaded)+102 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):预应用程序启动初始化方法启动类型Microsoft.Web.Helpers.PreApplicationStartCode引发异常,并显示以下错误消息:无法加载文件或程序集'System.Web.WebPages.Razor,Version = 3.0 .0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(来自HRESULT的异常:0x80131040).] System.Web.HttpRuntime.FirstRequestInit(HttpContext context)+9946024 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)+90 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context)+ 261
**This is the portion of my Web.Config**
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebMatrix.WebData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
I verified the version of each on Reference are the same as on Web.Config. Please help me. Thank you for your help.
Run Code Online (Sandbox Code Playgroud)
您在web.config中有这个绑定重定向,其中提到使用Razor 2.0而不是Razor 3.0,并且您尝试使用不绑定任何内容的Razor 3.0程序集:
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
您应该做的第一件事是,将绑定重定向更改为使用版本3.0:
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
还要确保web.config里面的Views文件夹中存在这些配置行:
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
Run Code Online (Sandbox Code Playgroud)
如果它仍然无效并且您不确定Razor软件包是否已正确安装,请尝试使用NuGet Gallery/Package Manager控制台命令(使用-reinstall开关)重新安装所需的软件包,然后执行上面的步骤:
Update-Package –reinstall Microsoft.AspNet.WebPages
Update-Package -reinstall Microsoft.AspNet.Razor
Run Code Online (Sandbox Code Playgroud)
注意 - 此程序集绑定表示正在使用MVC 4:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
我建议将MVC项目升级到5.0.0版,并按照此参考中的建议将Razor绑定更新到3.0.0版:
如何将ASP.NET MVC 4和Web API项目升级到ASP.NET MVC 5和Web API 2(Microsoft Docs)
类似问题:
运行时错误:无法加载文件或程序集'System.Web.WebPages.Razor,Version = 3.0.0.0
无法加载文件或程序集'System.Web.WebPages.Razor,Version = 3.0.0.0
| 归档时间: |
|
| 查看次数: |
16251 次 |
| 最近记录: |