asp.net-mvc - 无法加载文件或程序集'System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'ASP.NET MVC

标签 asp.net-mvc

我经历了很多之前已经回答过的答案,但是我很不幸运地找到了解决我问题的方法。这无法加载文件或程序集'System.Web.WebPages.Razor,版本= 3.0.0.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35'和我使用的许多其他文件。

****这是运行时错误:****

无法加载文件或程序集'System.Web.WebPages.Razor,版本= 3.0.0.0,区域性=中性,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. 


异常详细信息:System.IO.FileLoadException:无法加载文件或程序集'System.Web.WebPages.Razor,版本= 3.0.0.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自HRESULT的异常:0x80131040)

源错误:

当前Web请求的执行期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来标识有关异常的来源和位置的信息。

程序集加载跟踪:以下信息有助于确定为何无法加载程序集'System.Web.WebPages.Razor,版本= 3.0.0.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35'。

===预绑定状态信息===
日志:DisplayName = System.Web.WebPages.Razor,版本= 3.0.0.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35
(完全指定)
日志:Appbase = file:/// C:/ menupoly / abdulla / men1 / MenuSnaps /
日志:初始PrivatePath = C:\ menupoly \ abdulla \ men1 \ MenuSnaps \ bin

调用程序集:Microsoft.Web.Helpers,版本= 3.0.0.0,文化=中性,PublicKeyToken = 31bf3856ad364e35。

日志:此绑定在默认的加载上下文中开始。
日志:使用应用程序配置文件: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。
WRN:比较程序集名称会导致不匹配:主要版本
ERR:无法完成装配的设置(hr = 0x80131040)。探测终止。

堆栈跟踪:

[FileLoadException:无法加载文件或程序集'System.Web.WebPages.Razor,版本= 3.0.0.0,区域性=中性,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自HRESULT的异常:0x80131040)
Microsoft.Web.Helpers.PreApplicationStartCode.Start()+0

[InvalidOperationException:应用程序前启动初始化方法Microsoft.Web.Helpers.PreApplicationStartCode类型上引发了带有以下错误消息的异常:无法加载文件或程序集'System.Web.WebPages.Razor,版本= 3.0.0.0,文化=中性,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自HRESULT的异常:0x80131040)。
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection 1 methods, Func 1 setHostingEnvironmentCultures)+613
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1方法)+141
System.Web.Compilation.BuildManager.CallPreStartInitMethods(字符串preStartInitListPath,布尔值和isRefAssemblyLoaded)+102
System.Web.Compilation.BuildManager.ExecutePreAppStart()+157
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager,IApplicationHost appHost,IConfigMapPathFactory configMapPathFactory,HostingEnvironmentParametershostingParameters,PolicyLevel policyLevel,Exception appDomainCreationException)+531

[HttpException(0x80004005):应用程序前启动初始化方法Microsoft.Web.Helpers.PreApplicationStartCode类型上引发了带有以下错误消息的异常:无法加载文件或程序集'System.Web.WebPages.Razor,版本= 3.0 .0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自HRESULT的异常:0x80131040)。
System.Web.HttpRuntime.FirstRequestInit(HttpContext上下文)+9946024
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext上下文)+90
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext上下文)+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.

最佳答案

您在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>

您应该做的第一件事,将绑定重定向更改为使用版本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>

还要确保这些配置行存在于Views文件夹中的web.config中:
<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>

如果仍然无法正常工作,并且您不确定Razor软件包是否已正确安装,请尝试使用NuGet Gallery / Package Manager Console命令(使用-reinstall开关)重新安装所需的软件包,然后执行上述步骤:
Update-Package –reinstall Microsoft.AspNet.WebPages

Update-Package -reinstall Microsoft.AspNet.Razor

注意:此程序集绑定表明正在使用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>

我建议按照参考资料中的建议将MVC项目升级到5.0.0版,并将Razor绑定更新到3.0.0版:
How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2 (Microsoft Docs)
类似问题:
Runtime error: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0
Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0

关于asp.net-mvc - 无法加载文件或程序集'System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'ASP.NET MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46396243/

相关文章:

asp.net-mvc - 有没有办法重命名 RequestVerificationToken cookie 名称?

asp.net-mvc - MVC3 区域中的相对内容路径

asp.net-mvc - 在 asp.net mvc 中作为单个项目实现的区域与作为多个项目实现的区域有何优缺点

c# - ASP.NET MVC 3 : Multiple Html. RenderAction() 问题

c# - Angular 5 Uncaught( promise 中): Error: StaticInjectorError(AppModule)

asp.net - 触发表单例份验证的 User-Agent header 中的更改

c# - 在 ASP.NET MVC 中填充下拉列表

asp.net-mvc - ASP.NET MVC : upload multiple image files?

asp.net-mvc - 获取用户身份2.0的用户id

c# - 在没有外键 Entity Framework 的情况下设置一对多