Out of nowhere my ASP.NET MVC 4 solution gives me this error:
Inheritance security rules violated by type: \'System.Web.WebPages.Razor.WebPageRazorHos
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.
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.
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.
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:
System.Web.WebPages
, remove the reference and start using the System.Web.WebPages
NuGet packageSystem.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.
I was facing this error "inheritance security rules violated by type" in a Windows Service that used WCF components.
The same service worked on other server, but in a specific one, it didn't.
What fixed this error was commenting the following line in the app.config file.
<NetFx40_LegacySecurityPolicy enabled="true" />
We took a lot to figure it out, hope it helps somebody.