2

我在 mvc3 razor 中工作,我的项目很快运行正确,但我得到了错误

Error   3   Assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral,     PublicKeyToken=31bf3856ad364e35' uses 'System.Web.WebPages, Version=2.0.0.0, Culture=neutral,     PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced     assembly 'System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'        c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.Mvc.dll    MvcApplication1

我将 system.web.mvc.dll 和 System.Web.WebPages.Razor 文件从 mvc4 文件夹替换为 mvc3 文件夹。以及 web.config 中的一些更改,它开始正常工作。但现在几天后它向我显示以下错误消息

操作可能会破坏运行时

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Security.VerificationException:操作可能会破坏运行时的稳定性。

源错误:

在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

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) +196
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.GetHostFromConfig() +51
System.Web.WebPages.Razor.RazorBuildProvider.CreateHost() +57
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
System.Web.Mvc.BuildManagerViewEngine.FileExists(ControllerContext controllerContext, String virtualPath) +54
System.Web.Mvc.VirtualPathProviderViewEngine.GetPathFromGeneralName(ControllerContext controllerContext, List1     
locations, String name, String controllerName, String areaName, String cacheKey, String[]& searchedLocations) +197
System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext, String[] locations, String[] areaLocations, String locationsPropertyName, String name, String   controllerName, String cacheKeyPrefix, Boolean useCache, String[]& searchedLocations) +681
System.Web.Mvc.VirtualPathProviderViewEngine.FindView(ControllerContext controllerContext,  String     viewName, String masterName, Boolean useCache) +315
System.Web.Mvc.<>c__DisplayClassc.<FindView>b__b(IViewEngine e) +68
System.Web.Mvc.ViewEngineCollection.Find(Func2 lookup, Boolean trackSearchedPaths) +182
System.Web.Mvc.ViewEngineCollection.Find(Func2 cacheLocator, Func2 locator) +110
System.Web.Mvc.ViewEngineCollection.FindView(ControllerContext controllerContext, String     viewName, String masterName) +329
System.Web.Mvc.ViewResult.FindView(ControllerContext context) +135
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +230
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +74
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, 
Func1 continuation) +388
System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +72
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext,IList1filters, ActionResult actionResult) +303
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +844
System.Web.Mvc.Controller.ExecuteCore() +130
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +229
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +71
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
System.Web.Mvc.Async.<>c__DisplayClass8
1.<BeginSynchronous>b__7(IAsyncResult _) +42
System.Web.Mvc.Async.WrappedAsyncResult
1.End() +152
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +75
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +31
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +61
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +118
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

我的 web.config 中的设置如下

<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
 <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
 <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
 <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
 <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </assemblies>

请任何人帮我解决这个问题。

4

2 回答 2

0

您是否安装了 .NET Framework 4.5 或 Visual Studio 2012?问题很可能是框架中的错误。您可以在这里找到答案:

http://elegantcode.com/2012/08/23/net-4-5-operation-could-destabilize-the-runtime-yikes/

于 2013-01-29T22:47:42.763 回答
0

我们的一个项目也有类似的问题。我们一直在使用 MVC3 并尝试升级到 MVC4。我们还升级到 Razor 2.0。原来 web.configs 并没有按预期更新。检查 ~/Views 文件夹中的 Web 配置以及根 web.config 并确保程序集绑定重定向正确且所有程序集引用正确。我们这样做了,问题就消失了

于 2018-01-03T20:49:47.873 回答