Home > .NET, MVC, Vs2012 > Errors updating an MVC 4 project

Errors updating an MVC 4 project

2013/11/12

An MVC project by default uses NuGet as package updater, a concept similar to the java (and Android SDK) packages.

This is good, but sometimes leads to problems.

If you start an MVC 4 project from scratch with Visual Studio 2012, it uses an old version of Entity Framework (by default for MVC 4 is EF5).

Using the NuGet package updater there are a lot of updates , from jQuery to EF which is migrated to EF6.

This morning i updated an MVC4 project , and nothing was working…

Launching the project from Visual Studio i got

[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:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\4cf795a8\95e0656c\assembly\dl3\84c052c7\541b674e_ffdece01\System.Web.WebPages.Razor.dll’.

I tried to delete the Windows.Microsoft.NET (2 and 4, either 32 and 64 bit) Temporary ASP.NET Files , clean the project, delete all possible temp files…nothing.

The solution was to insert in the main web.config these lines:

<runtime>
	<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
		<dependentAssembly>
			<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
			<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
		</dependentAssembly>
	</assemblyBinding>
</runtime>

Well, at this point the site was complaining something about Microsoft.Data.Edm ..deleted from bin directory dll and xml file, it will be recreated.

Another launch , this time the error is

Inheritance security rules violated by type: ‘System.Web.Mvc.MvcWebRazorHostFactory’. Derived types must either match the security accessibility of the base type or be less accessible

This is corrected changing in the Views folder web.config the version in the below line from 4 to 5 , so we have

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

Finally the web site is working.

Advertisements
Categories: .NET, MVC, Vs2012
%d bloggers like this: