安装ASP.NET MVC 4 Beta后引发InvalidCastException

在使用ASP.NET MVC 3的机器上安装ASP.NET MVC 4 Beta后,我收到以下异常。

System.InvalidCastException未被用户代码处理消息= [A] System.Web.WebPages.Razor.Configuration.HostSection不能转换为[B] System.Web.WebPages.Razor.Configuration.HostSection。 类型A来自位于'C: Windows Microsoft.Net assembly GAC_MSIL System'上下文'Default'中的'System.Web.WebPages.Razor,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35' .Web.WebPages.Razor v4.0_1.0.0.0__31bf3856ad364e35 System.Web.WebPages.Razor.dll”。 类型B源于位于'C: Windows Microsoft.Net assembly GAC_MSIL System'上下文'Default'中的'System.Web.WebPages.Razor,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35' .Web.WebPages.Razor v4.0_2.0.0.0__31bf3856ad364e35 System.Web.WebPages.Razor.dll”。 来源= System.Web.WebPages.Razor

堆栈跟踪:

在System.Web.WebPages.Razor.WebRazorHostFactory.GetRazorSection(String virtualPath)System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String virtualPath,String physicalPath)at System.Web.WebPages.Razor.RazorBuildProvider.GetHostFromConfig()at System.Web.WebPages.Razor.RazorBuildProvider.CreateHost()在System.Web.WebPages.Razor.RazorBuildProvider.EnsureGeneratedCode()在System.Web.WebPages.Razor.RazorBuildProvider.get_CodeCompilerType()在System.Web.Compilation.BuildProvider。在System.Web.Compilation的System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProvider()处的System.Web.Compilation.BuildProvidersCompiler.PerformBuild()处的System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)处的GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)。 BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath,Boolean noBuild,Boolean allowCrossApp,Boolean allowBuildInPrecompile,Boolean throwIfNotFound,Boolean ensureIsUpToDate)a 在System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath,HttpContext context,Boolean)时,System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext上下文,VirtualPath virtualPath,布尔noBuild,布尔allowCrossApp,布尔allowBuildInPrecompile,布尔throwIfNotFound,布尔ensureIsUpToDate)在System.Web.Mvc上System.Web.Mvc.BuildManagerViewEngine.FileExists(ControllerContext controllerContext,字符串virtualPath)上System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.FileExists(String virtualPath)上的allowCrossApp,布尔throwIfNotFound) .VirtualPathProviderViewEngine.GetPathFromGeneralName(ControllerContext controllerContext,List`1 locations,String name,String controllerName,String areaName,String cacheKey,String []&searchingLocations)at System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext,String [] locations, String [] areaLocations,String locationsPropertyName,S (System.Web.Mvc.ViewEngineCollection)处的System.Web.Mvc.VirtualPathProviderViewEngine.FindView(ControllerContext controllerContext,String viewName,String masterName,Boolean useCache)中的名称,字符串controllerName,字符串cacheKeyPrefix,布尔useCache,字符串[]和SearchingLocations) System.Web.Mvc.ViewEngineCollection.FindView(System.Web.Mvc.ViewEngineCollection.Find(ControllerContext controllerContext,String viewName,String masterName)上System.Web.Mvc.ViewEngineCollection.Find(Func`2查找,布尔trackSearchedPaths)c__DisplayClassc.b__b(IViewEngine e)在System.Web.Mvc的System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,ActionResult actionResult)上的System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext上下文)中的.Web.Mvc.ViewResult.FindView(ControllerContext上下文) ControllerActionInvoker。<> c__DisplayClass1c.b__19()at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter,ResultExecutingContext preContext,Fun System.Web.Mvc.ControllerActionInvoker。<> c__DisplayClass1c。<> c__DisplayClass1e.b__1b()at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext,IList`1 filters,ActionResult actionResult)at System。 Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,String actionName)System.Web.Mvc.Controller.ExecuteCore()at [project_namespace] .Controllers.GlobalizationController.ExecuteCore()in [file_path] at System.Web.Mvc.ControllerBase在System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)上System.Web.Mvc.MvcHandler .Execute(RequestContext requestContext)<> c__DisplayClass6。<> c__DisplayClassb.b__5()at System .Web.Mvc.Async.AsyncResultWrapper。<> c__DisplayClass1.b__0()at System.Web.Mvc.Async.AsyncResultWrapper。<> c__DisplayClass8`1.b__7(IAsyncResult _)at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult `1.End()在System.Web.Mvc.MvcHandler System.Web.Mvc.SecurityUtil.b__0上的System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)上的System.Web.Mvc.SecurityUtil.b__0(Action f)上的c__DisplayClasse.b__d()(IAsyncResult asyncResult) System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()at System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔&完成同步)

这完全阻止了我,虽然我想保留测试版,但我可能需要将其完全删除才能排除异常。


尝试在web.config中添加以下内容:

<appSettings>
  <add key="webpages:Version" value="1.0.0.0"/>
</appSettings>

这个问题可能是由于多个构建提供商正在注册以及最近的获胜。


我有同样的问题,但是当将ASP.NET MVC 3迁移到ASP.NET MVC 4时。这样我就得到了这个主题。 我找到了解决这个问题的办法,但是它的来源不同,它不是来自WebPages版本。

我遵循官方指南(可以这么说)将ASP.NET MVC 3项目升级到ASP.NET MVC 4。

为了解决这个问题,你必须添加Web.Config(可能是以前添加的):

<runtime><!-- Should be there by default, near end -->
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><!-- Should be there by default -->
    <dependentAssembly>..</dependentAssembly><!-- Should be there by default -->
        ... some other dependecy redirects ...

    <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages.Razor"
            publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
    </dependentAssembly>

        ... some other dependency redirects ...
    </assemblyBinding>
</runtime>

同样在笔记中没有提到要将System.Web.Helpers的Reference从1.0.0.0更改为2.0.0.0(删除并添加新的)。


还有一个,相当晚的解决方案......我遇到了同样的问题。 这里列出的所有修复(谢谢大家!!!)但无法通过错误。 最后,无奈之下,我在Views目录中找到了一个web.config文件。 在这个文件中,我发现了几个对System.Web.Mvc版本的引用,并将它们全部提升到“4.0.0.0”。 更重要的是,我发现了以下行,并将“system.web.webPages.Razor”的版本号从“1.0.0.0”更新为“2.0.0.0”,突然之间,所有事情都再次运行。 希望这会帮助别人。

<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
  <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>

Steve G.

链接地址: http://www.djcxy.com/p/72689.html

上一篇: InvalidCastException is thrown after installing ASP.NET MVC 4 Beta

下一篇: signature does not match expected value oAuth Tumblr Request