Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()'

asp.net Mvc

asp.net Mvc Problem Overview


Update: same for mvc 4 to mvc 5.

I started a new mvc 4 project and migrated an mvc 3 project in it (controllers/models/scripts etc). While everything compiles now i get the following error:

>Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)' failed.

I can't find anything on the web with this error. The error hits before getting into the application start.

I tried reinstalling all assemblies with nuget, putting a 'clean' web.config to no avail.

Anyone had this problem before?

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

For me this error was because I did NOT have Microsoft.AspNet.WebHelpers installed after updating from MVC 4 to MVC 5. It was fixed by installing the NuGet package

Install-Package -Id  Microsoft.AspNet.WebHelpers

Solution 2 - asp.net Mvc

If you are getting the error

>Attempt by security transparent method ‘WebMatrix.WebData.PreApplicationStartCode.Start()’ to access security critical method ‘System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)’ failed.

In order to fix this install this package using NuGet package manager.

Install-Package Microsoft.AspNet.WebHelpers

After that , probably you will get another error

>Cannot load WebMatrix.Data version 3.0.0.0 assembly

to fix this install this package using NuGet package manager.

Install-Package Microsoft.AspNet.WebPages.Data

Solution 3 - asp.net Mvc

For anyone landing here who is trying to upgrade from MVC 4 to MVC5, I was able to resolve this issue by following the instructions at http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2.

I also had to install the "Microsoft.AspNet.WebApi.WebHost" package from nuget. But that's it.

Oh, and I had to create this appSetting: <add key="owin:AutomaticAppStartup" value="false" />

:)

Solution 4 - asp.net Mvc

I tried all of the above solutions and it still wouldn't work, until I found that the web.config compilation element was referencing version 2.0.0.0 of WebMatrix.Data and WebMatrix.WebData. Changing the version of those entries in the web.config to 3.0.0.0 helped me.

Solution 5 - asp.net Mvc

I've been struggling with a similar issue when upgrading mvc 4 to mvc 5:

>Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed.

The delete extra files check box in the publish dialog solved it for me.

Solution 6 - asp.net Mvc

Reinstalling Microsoft.AspNet.WebHelpers works for me

Update-Package –reinstall Microsoft.AspNet.WebHelpers

Solution 7 - asp.net Mvc

Just one more suggestion... This was caused for me by some old dll's from an MVC 3 project after upgrading to MVC 5 in the site bin folder on the deployment server. Even though these dll's were no longer used by the code base they appeared to be causing the problem. Cleaned it all out and re-deployed and it was fine.

Solution 8 - asp.net Mvc

You may also get :

> Could not load file or assembly 'WebMatrix.Data, Version=3.0.0.0, > Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its > dependencies. The located assembly's manifest definition does not > match the assembly reference. (Exception from HRESULT: 0x80131040)

This has moved to this package

 Install-Package Microsoft.AspNet.WebPages.Data

You should probably do a clean build before attempting any of the answers to this question and after updating packages

Solution 9 - asp.net Mvc

Deleting all files from bin and then rebuilding the solution worked for me.

Solution 10 - asp.net Mvc

Here is how I fixed this issue:

Open the nuget package manager console and install the below nuget packages:

Install-Package WebMatrix.Data
Install-Package Microsoft.AspNet.WebHelpers
Update-Package

Clean the solution, rebuild and my asp.net web app starts working!

Solution 11 - asp.net Mvc

For me this error was caused by DotNetOpenAuth not being compatible with MVC5 after upgrading from MVC4 to MVC5. Uninstalling Microsoft.Web.WebPages.OAuth fixed the problem.

Solution 12 - asp.net Mvc

I have removed it from my references.Then run this in Package Manager Console

Install-Package WebMatrix.Data

Finally add WebMatrix.WebData assembly to references,and rebuild project.It works for me.I hope it solves your problem too.

Solution 13 - asp.net Mvc

I installed webapi with it via the helppages nuget package. That package replaced most of the asp.net mvc 4 binaries with beta versions which didn't work well together with the rest of the project. Fix was to restore the original mvc 4 dll's and all was good.

Solution 14 - asp.net Mvc

I had the same problem, I had to update MVC Future (Microsoft.AspNet.Mvc.Futures)

Install-Package Microsoft.AspNet.Mvc.Futures

Solution 15 - asp.net Mvc

For me this errors resolved by adding

<system.web>
 <trust level="Full">
 </system.web>

in web.config

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionElger MensonidesView Question on Stackoverflow
Solution 1 - asp.net MvcMichaelView Answer on Stackoverflow
Solution 2 - asp.net MvcAnushkaView Answer on Stackoverflow
Solution 3 - asp.net MvcAlex DreskoView Answer on Stackoverflow
Solution 4 - asp.net MvcPaulView Answer on Stackoverflow
Solution 5 - asp.net MvcEdward OlamisanView Answer on Stackoverflow
Solution 6 - asp.net MvcPablo ClausView Answer on Stackoverflow
Solution 7 - asp.net MvcchrisView Answer on Stackoverflow
Solution 8 - asp.net MvcSimon_WeaverView Answer on Stackoverflow
Solution 9 - asp.net MvctheskhanView Answer on Stackoverflow
Solution 10 - asp.net MvcMostafaView Answer on Stackoverflow
Solution 11 - asp.net MvcDean NorthView Answer on Stackoverflow
Solution 12 - asp.net MvcAli Gol GolView Answer on Stackoverflow
Solution 13 - asp.net MvcElger MensonidesView Answer on Stackoverflow
Solution 14 - asp.net MvcPvtVandalsView Answer on Stackoverflow
Solution 15 - asp.net MvcOmar KamelView Answer on Stackoverflow