"Operation may destabilize runtime" when trying to upgrade from MVC3 to MVC4

Server Error in '/' Application. 

What is a good way to fix this problem? I allow to debug everything through global.asax and no errors there.

 Operation could destabilize the runtime. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Security.VerificationException: Operation could destabilize the runtime. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [VerificationException: Operation could destabilize the runtime.] System.Web.Mvc.Razor.MvcWebPageRazorHost.GetRidOfNamespace(String ns) +32 System.Web.Mvc.Razor.MvcWebPageRazorHost..ctor(String virtualPath, String physicalPath) +199 System.Web.Mvc.MvcWebRazorHostFactory.CreateHost(String virtualPath, String physicalPath) +113 System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfigCore(RazorWebSectionGroup config, String virtualPath, String physicalPath) +422 System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String virtualPath, String physicalPath) +228 System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String virtualPath) +38 System.Web.WebPages.Razor.RazorBuildProvider.CreateHost() +51 System.Web.WebPages.Razor.RazorBuildProvider.get_Host() +56 System.Web.WebPages.Razor.RazorBuildProvider.EnsureGeneratedCode() +92 System.Web.WebPages.Razor.RazorBuildProvider.get_CodeCompilerType() +54 System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider) +59 System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() +209 System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +15 System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +9929933 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +299 System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +103 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) +165 System.Web.Compilation.BuildManager.GetObjectFactory(String virtualPath, Boolean throwIfNotFound) +33 System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.FileExists(String virtualPath) +40 
+6
source share
2 answers

I had exactly the same problem, although my project was .Net 4.5. I solved this by completing step 7 Upgrading an ASP.NET MVC 3 project to ASP.NET MVC 4

It is copied here as follows:

7. If the project references any third-party libraries compiled using previous versions of ASP.NET MVC, open the root Web.config file and add the following three bindingRedirect elements in the configuration section:

  <configuration> <!--... elements deleted for clarity ...--> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration> 
+4
source

This is a very strange thing - and the information provided is not enough to reproduce it ... so some things can lead to what you see:

  • Intellitrace (turn it off and see if it helps)
  • used "old controls" (especially V 1.1), comment on them and see if it helps
  • Trusted Level, change to [assembly: SecurityRules(SecurityRuleSet.Level1)] in AssemblyInfo.cs and see if it helps

It may also be a bug in the .NET 4.5 runtime that acts upon installation as a replacement for replacing .NET 4 and is used even if your code is for .NET 4 only!

From a related article, a fix to the .Net 4.5 / 4.0 runtime has since been created by Microsoft as a fix: http://support.microsoft.com/kb/2748645

+3
source

Source: https://habr.com/ru/post/924293/


All Articles