我得到Unable来施放
类型的对象ASP._Page__ViewStart_cshtml'键入'System.Web.WebPages.StartPage'
当我运行我的MVC应用程序时。
我在搜索时找到的每个答案都告诉我确保 _ViewStart 文件位于我的 视图 文件夹,它是。更奇怪的是,我将完全相同的项目文件从旧的Win 7 PC复制到我的新Win 10笔记本电脑。该应用程序在旧PC上运行良好,但在新笔记本电脑上出现上述错误。我也是从Visual Studio 2015运行。
还有其他想法吗?
完整的错误消息:
[InvalidCastException: Unable to cast object of type 'ASP._Page__ViewStart_cshtml' to type 'System.Web.WebPages.StartPage'.]
System.Web.WebPages.StartPage.GetStartPage(WebPageRenderingBase page, String fileName, IEnumerable`1 supportedExtensions) +236
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +163
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +176
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
System.Web.Mvc.Controller.ExecuteCore() +105
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +88
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +16
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +28
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9765901
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
视图文件夹中的Web配置:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="DevExpress.Utils" />
<add namespace="DevExpress.Web.ASPxClasses" />
<add namespace="DevExpress.Web.ASPxGridView" />
<add namespace="DevExpress.Web.ASPxGridView.Export" />
<add namespace="DevExpress.Web.ASPxEditors" />
<add namespace="DevExpress.Web.ASPxCallbackPanel" />
<add namespace="DevExpress.Web.ASPxMenu" />
<add namespace="DevExpress.Web.ASPxNavBar" />
<add namespace="DevExpress.Web.ASPxPopupControl" />
<add namespace="DevExpress.Web.ASPxRoundPanel" />
<add namespace="DevExpress.Web.ASPxSplitter" />
<add namespace="DevExpress.Web.ASPxTabControl" />
<add namespace="DevExpress.Web.ASPxTreeView" />
<add namespace="DevExpress.Web.ASPxUploadControl" />
<add namespace="DevExpress.Web.ASPxHtmlEditor" />
<add namespace="DevExpress.Web.ASPxSpellChecker" />
<add namespace="DevExpress.XtraCharts"/>
<add namespace="DevExpress.XtraCharts.Web" />
<add namespace="DevExpress.XtraReports" />
<add namespace="DevExpress.XtraReports.UI" />
<add namespace="DevExpress.XtraReports.Web" />
<add namespace="DevExpress.Web.Mvc" />
<add namespace="DevExpress.Web.Mvc.UI" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
<add key="DalManagerType" value="TimeTracker.DalEF.DalManager,TimeTracker.DalEF"/>
<add key="DalManagerTypeFMS" value="FMSv3.DALEF.DalManager,FMSv3.DALEF" />
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
答案 0 :(得分:0)
案例1:
重新组织项目时出现copy+paste
错误。
解决方案:只需删除@inherits System.Web.Mvc.WebViewPage
案例2:
如果您将_ViewStart.cshtml
远离Views文件夹移动到项目的根文件夹。
解决方案:_ViewStart.cshtml
文件只能放入Views文件夹中。 (与web.config
相同的级别)
案例3:
如果您将MVC3升级到4.5框架并面临此错误。
解决方案:只需将@inherits System.Web.Mvc.ViewStartPage
添加到_ViewStart.cshtml