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?
对我来说这个错误是因为我从MVC 4更新到MVC 5之后没有安装Microsoft.AspNet.WebHelpers。它是通过安装NuGet包修复的
Install-Package -Id Microsoft.AspNet.WebHelpers
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
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" />
:)
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.
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.
重新安装Microsoft.AspNet.WebHelpers
适合我
Update-Package –reinstall Microsoft.AspNet.WebHelpers
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.
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
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!
从bin中删除所有文件然后重建解决方案对我有用。
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.
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.
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.
我遇到了同样的问题,我不得不更新MVC Future(Microsoft.AspNet.Mvc.Futures)
Install-Package Microsoft.AspNet.Mvc.Futures
For me this errors resolved by adding
<system.web>
<trust level="Full">
</system.web>
in web.config
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.