C# Razor 2 到 Razor 3 MVC 5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19949676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Razor 2 to Razor 3 MVC 5
提问by Dylan Corriveau
I've been working on an MVC 4 solution, and I've been trying to upgrade it to MVC 5. I've followed the steps outlined here.
我一直在研究 MVC 4 解决方案,并且一直在尝试将其升级到 MVC 5。我已按照此处概述的步骤进行操作。
I've followed it, and now whenever I run the MVC Application, it gives me this error message:
我遵循了它,现在每当我运行 MVC 应用程序时,它都会给我以下错误消息:
[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to
[B]System.Web.WebPages.Razor.Configuration.HostSection.
Type A originates from
'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location
'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.
Type B originates from 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location
'C:\Users\User\AppData\Local\Temp\Temporary ASP.NET
Files\root5ac028\de53a189\assembly\dl3\c2c0a4b5e8099e_40e0ce01\System.Web.WebPages.Razor.dll'.
Does anyone know how this could have originated? or how it can be solved? I've looked around thus far? I've tried changing the web.config files, with no avail...
有谁知道这可能是如何起源的?或者如何解决?到目前为止我环顾四周?我试过更改 web.config 文件,但无济于事......
采纳答案by Dima
In your Web.config
(-s) make sure assemblyBinding
contains the proper version for the assembly System.Web.WebPages.Razor
and System.Web.Mvc
.
在您的Web.config
(-s) 中确保assemblyBinding
包含正确的程序集版本System.Web.WebPages.Razor
和System.Web.Mvc
.
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" 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.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
And make sure that razor sectionGroup
in ConfigSections
reference latest versions as well:
并确保剃刀sectionGroup
在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>
回答by Jakub Konecki
Looks like you still have a reference to Razor 2.0 dll.
看起来您仍然有对 Razor 2.0 dll 的引用。
Check your project references' properties - especially 'Use specific version' one.
检查您的项目引用的属性 - 特别是“使用特定版本”之一。
回答by sushama
Check for version in web.config. If it again gives an error, try to clean the solution and rebuild it. Also check for project's Bin folder, removes old references from bin folder and rebuild the project solution.
检查 web.config 中的版本。如果它再次出现错误,请尝试清理解决方案并重建它。还要检查项目的 Bin 文件夹,从 bin 文件夹中删除旧引用并重建项目解决方案。