Error: Inheritance security rules violated by type: 'System.Web.WebPages.Razor.WebPageRazorHost'

ⅰ亾dé卋堺 提交于 2019-11-28 22:32:10

From my friend Claudio Redi's comment the solusion of this problem is:

Try removing the System.Web.Razor assembly binding in the web.config if present. http://forums.asp.net/t/1968686.aspx?Installed+Nuget+package+Razor+Engine+whole+system+stops

Go to Web.config and Search for the Assembly name="System.Web.Razor" and comment as follow.

 <!--<dependentAssembly>
    <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>-->

After Commenting save and run the project,it will work fine.

For me commenting of "System.Web.Razor" from web config did not worked.Here are the things i did to resolve this. Search your whole solution for references to MvcWebRazorHostFactory. you will find something like below in config file.

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Change Version=4.0.0.0 to Version=5.0.0.0 and it will work.

Commenting out the binding redirect as suggested above worked for 3 of my older machines but did not work on a fourth, newer machine.

Turns out that commenting out the binding redirect apparently just allows System.Web.Razor version 1.0.0.0 to be found/used, but my 4th machine, a newly built machine, lacked System.Web.Razor.DLL version 1.0.0.0.

Copying System.Web.Razor version 1.0.0.0 DLL to that machine in the website's bin folder, then my problem was solved. Removing 1.0.0.0 version DLL and putting version 2.0.0.0 back, the problem returned.

Another discovery I made regarding the machines where the bindingRedirect approach did work was that once RazorEngine worked for me after having commented out the binding redirect, I could un-comment-out the binding redirect and RazorEngine continued to work.

Gustavo Russo

Your project references are in turn linked to different versions of Microsoft.AspNet.Razor library, that are incompatibles between them.

Your stack trace points to System.Web.WebPages dll, which is probably linking to a version of the Microsoft.AspNet.Razor older that the one referenced by other NuGet package (for example Microsoft.AspNet.Mvc).

To fix the problem:

  1. If you are directly referencing the System.Web.WebPages, remove the reference and start using the System.Web.WebPages NuGet package
  2. If you are already using the System.Web.WebPages NuGet package, update it to the same version of the Microsoft.AspNet.Razor package that you are already using in your project.

This will fix your current error, but probably will result in a new one appearing, especially if you are migrating or mixing packages between Microsoft.AspNet.Mvc versions. In this case, you need to sync the versions of all your NuGet packages related to MVC.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!