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

16

183

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?

Surrounding answered 29/7, 2013 at 14:23 Comment(0)
S
256

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
Syndic answered 24/10, 2013 at 14:11 Comment(4)
This solved the issue for me; it did create some namespace issues with my Resources class, but I changed it to Properties.Resources.xxxxx and the issues were fixed.Intumescence
I ran this and it didn't work...but then fortunately I saw that in another answer, there's a second command to run: https://mcmap.net/q/135781/-attempt-by-security-transparent-method-39-webmatrix-webdata-preapplicationstartcode-start-39Eryn
this fxed it for me but I also needed the below in assembly bindings code<dependentAssembly> <assemblyIdentity name="WebMatrix.WebData" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly>codeTardy
I install above mentioned package and problem is gone. I used NUget UI to install it and that also installed all the dependencies for meSlesvig
O
205

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
Osmosis answered 23/3, 2014 at 5:39 Comment(7)
I had this exact error when upgrading to VS 2015 RTM. Same code ran just fine with VS 2013, the only difference being a new .config file that 2015 generates for IIS that I suspect the 2013 IISExpress ignores. This answer fixed this case too, add both nugets.Sleety
It should be mentioned that I was not successful in running my website with VS2015 RTM at all. Installing Microsoft.AspNet.WebHelpers fixed the YSOD, but then I got a timeout due to some sql access rights instead. The exact same code ran just fine in VS2013.Sleety
I've encountered this problem using VS 2013 Express Edition when upgrading from ASP .NET MVC 4 to ASP .NET MVC 5. This was helpful since @Osmosis told the second problem with a solution.Wallachia
I get this error when I tried to run my solution in VS 2015. It runs perfectly fine in VS 2013. Installing the 2 packages as suggested works but I am not sure why I need to install them. I have other solutions that I developed in VS 2013 that do not get this error in VS 2015.Induce
Is there a way to fix this problem without adding these extra Nugets? We have a single developer on VS2015 and he is the only one getting the problem. Like John81, I have no idea why we should be forced to install the 2 nugets and would prefer not to. Again like John81, we have other MVC 5 projects that work fine for the 2015 developer, so there must be something particular to this one app that perhaps we can remove to get rid of the error - but what is it?Dahl
We've found that VS2015 decides to put some WebMatrix DLLs in the webapp's bin directory on compilation - VS2013 doesn't do that. I don't know where 2015 is getting these DLLs from, but they must be a different version to the DLLs that get loaded in from the GAC (I guess) when you start up the app that's been compiled by VS2013 without the WebMatrix DLLS explicitly included in the app bin directory. Note that, if you delete the 4 WebMatrix files from the 2015 output, and restart IIS, the problem goes away.Dahl
@SimonGreen I wound up tracing my "ghost" WebMatrix references to the MySql.Web library - that project references WebMatrix for the Membership bits (which I don't actually use). I would assume you have something similar. Not sure why VS2015 treats those references any different than 2013, though.Sanmicheli
N
19

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" />

:)

Nielsen answered 21/10, 2013 at 19:39 Comment(0)
C
15

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.

Coldhearted answered 5/11, 2013 at 19:5 Comment(0)
E
11

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.

Elora answered 4/1, 2014 at 8:31 Comment(1)
I had this error in my SharePoint 2013 Provider Hosted App (ASP.NET MVC 5, deployed to Azure), "delete additional files" in the publish dialog solved it for me, too.Margaritamargarite
G
8

Reinstalling Microsoft.AspNet.WebHelpers works for me

Update-Package –reinstall Microsoft.AspNet.WebHelpers
Gunther answered 4/11, 2014 at 13:7 Comment(0)
O
6

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

Oilskin answered 25/4, 2014 at 16:52 Comment(0)
T
6

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.

Threecornered answered 7/5, 2014 at 20:45 Comment(1)
This was the reason of my error. I was having old and the new files in the bin folder. thanksStandridge
C
3

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

Cookbook answered 4/6, 2014 at 16:18 Comment(0)
A
3

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!

Alvarez answered 6/8, 2015 at 21:45 Comment(0)
T
1

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.

Tatary answered 23/10, 2013 at 11:28 Comment(0)
P
1

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.

Pressroom answered 25/12, 2014 at 21:26 Comment(0)
S
0

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.

Surrounding answered 30/7, 2013 at 8:9 Comment(0)
J
0

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

Install-Package Microsoft.AspNet.Mvc.Futures
Jarrodjarrow answered 2/10, 2015 at 14:21 Comment(0)
F
0

Just to give a really concrete example for a legacy solution I faced the problem right today (in 2023). In my case

  • using Visual Studio 2017
  • I upgraded AspNet.MVC from 4.0.0.1 to 5.2.9 running on .Net 4.5.2

But I still had the package

  • WebMatrix.WebData, Version 2.0.30506. for .Net4 installed

You have to

  • remove WebMatrix.WebData, Version 2.0 completely

That is what caused the error. As explained here and in other sources like [https://www.wikitechy.com/fix-error/attempt-by-security-transparent-method-web-matrix-web-data-pre-application-start-code-start] the installation of

  • Microsoft.AspNet.WebHelpers, Version 3.2.9

This will bring

  • WebMatrix.WebData, Version 3.0.0

Be sure that all other referenced assemblies are also updated that way.

Freidafreight answered 17/2, 2023 at 17:42 Comment(0)
S
-2

For me this errors resolved by adding

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

in web.config

Shipman answered 15/4, 2019 at 22:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.