Ahs*_*mad 33 c# exception asp.net-mvc-4 assembly-binding-redirect
在我的asp.net mvc 4解决方案给我这个错误的地方没有:
违反类型的继承安全规则:'System.Web.WebPages.Razor.WebPageRazorHost'.派生类型必须与基本类型的安全可访问性匹配,或者不太容易访问.
我搜索了这个问题,每个人都说当任何人将这个解决方案从一个版本更新到另一个版本时就已经发生了.但我没有更新我的解决方案,只需将IDE从VS12更改为VS13.这是造成问题的原因吗?
完整堆栈跟踪如下:
[TypeLoadException:违反类型的继承安全规则:System.Web.WebPages.Razor.WebPageRazorHost'.派生类型必须要么匹配基本类型的安全性或可访问性不太接近.] System.Web.WebPages.Razor.RazorBuildProvider.get_CodeCompilerType()0 System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)59系统. Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()+ 209 System.Web.Compilation.BuildProvidersCompiler.PerformBuild()+30 System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)+9971917 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.GetVir tualPathObjectFactory(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 Microsoft.Web.Mvc.FixedRazorViewEngine.Microsoft.Web.Mvc.IViewEngineProxy.FileExists(ControllerContext controllerContext,String virtualPath)+ 42 Microsoft.Web.Mvc.ViewEngineFixWorker
1.FileExists(ControllerContext controllerContext, String virtualPath) +57 Microsoft.Web.Mvc.<>c__DisplayClass4.<GetPathFromGeneralName>b__0(String path) +66 System.Web.WebPages.DefaultDisplayMode.GetDisplayInfo(HttpContextBase httpContext, String virtualPath, Func2 virtualPathExists)+90 System.Web.WebPages.<> c__DisplayClassb.b__8(IDisplayMode模式)+66 System.Linq.WhereSelectListIterator2.MoveNext() +103 System.Linq.Enumerable.FirstOrDefault(IEnumerable1 source,Func2 predicate) +94 System.Web.WebPages.DisplayModeProvider.GetDisplayInfoForVirtualPath(String virtualPath, HttpContextBase httpContext, Func2 virtualPathExists,IDisplayMode currentDisplayMode,Boolean requireConsistentDisplayMode)+297 System.Web.WebPages.DisplayModeProvider.GetDisplayInfoForVirtualPath(String virtualPath,HttpContextBase httpContext,Func2 virtualPathExists, IDisplayMode currentDisplayMode) +108 Microsoft.Web.Mvc.ViewEngineFixWorker1.GetPathFromGeneralN ame(ControllerContext controllerContext,List1 locations, String name, String controllerName, String areaName, String cacheKey, String[]& searchedLocations) +653 Microsoft.Web.Mvc.ViewEngineFixWorker1.GetPath(ControllerContext controllerContext,String [] locations,String [] areaLocations,String locationsPropertyName,String name,String controllerName,String cacheKeyPrefix,Boolean useCache,String []&searchingLocations)+1508 Microsoft.Web. Mvc.ViewEngineFixWorker1.FindView(ControllerContext controllerContext, String viewName, String masterName, Boolean useCache) +329 Microsoft.Web.Mvc.FixedRazorViewEngine.FindView(ControllerContext controllerContext, String viewName, String masterName, Boolean useCache) +66 System.Web.Mvc.<>c__DisplayClassc.<FindView>b__b(IViewEngine e) +68 System.Web.Mvc.ViewEngineCollection.Find(Func2查找,布尔trackSearchedPaths)182 System.Web.Mvc.ViewEngineCollection.Find(Func键2 cacheLocator, Func2定位器)110 System.Web.Mvc.ViewEngineCollection.FindView(ControllerContext controllerContext,字符串的viewName,字符串masterName)329系统. Web.Mvc.ViewResult.FindView(ControllerContext上下文)135 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext上下文)230 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,的ActionResult的ActionResult)39的System.Web. Mvc.<> c__DisplayClass1a.b__17()+74 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter过滤器,ResultExecutingContext preContext,Func1 continuation) +388 System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +72 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1过滤器,Ac tionResult actionResult)+303 System.Web.Mvc.Async.<> c__DisplayClass2a.b__20()+155 System.Web.Mvc.Async.<> c__DisplayClass25.b__22(IAsyncResult asyncResult)+184 System.Web.Mvc.Async.WrappedAsyncResult1.End() +136 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40 System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +40 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +47 System.Web.Mvc.Async.WrappedAsyncResult1.End()151 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult的asyncResult,对象标签)59 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult的asyncResult,对象标签)40的System.Web .Mvc.Controller.EndExecuteCore(IAsyncResult的asyncResult)44 System.Web.Mvc.Async.<> c__DisplayClass4.b__3(IAsyncResult的AR)47 System.Web.Mvc.Async.WrappedAsyncResult1.End() +151 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.Controller.EndExecute(IAsyncResult asyncResult) +39 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39 System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +45 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +47 System.Web.Mvc.Async.WrappedAsyncResult1.End()151的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.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) 40 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult的结果)38 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.E xecute()+9651116 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)+155
Ahs*_*mad 47
从我的朋友Claudio Redi的评论来看,这个问题的解决方案是:
尝试删除web.config中的System.Web.Razor程序集绑定(如果存在).http://forums.asp.net/t/1968686.aspx?Installed+Nuget+package+Razor+Engine+whole+system+stops
Deb*_*ash 13
转到Web.config并搜索程序集名称="System.Web.Razor"并注释如下.
<!--<dependentAssembly>
<assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>-->
Run Code Online (Sandbox Code Playgroud)
在评论保存并运行项目后,它将正常工作.