Git Product home page Git Product logo

Comments (5)

rpannekoek avatar rpannekoek commented on July 19, 2024

When an exception occurs while rendering a Region or Entity View, DXA tries to render the error using the SectionError View (which is normally in your Web App in \Views\Shared\SectionError.cshtml). It passes a Model of type HandleErrorInfo (which is expected by that View).

from dxa-web-application-dotnet.

jhorsman avatar jhorsman commented on July 19, 2024

I have a Views/Shared/SectionError.cshtml in my website project. Should it be registered somewhere? I see that it indeed expects the System.Web.Mvc.HandleErrorInfo model which is mentoned in the error message as well.

from dxa-web-application-dotnet.

jhorsman avatar jhorsman commented on July 19, 2024

Here is some more stacktrace

2016-12-13 15:42:57,429 [5] ERROR - No View Model registered for View 'MyModule:EComWidget:Categories'. Check that you have registered this View in the 'MyModule' area registration.
Sdl.Web.Common.DxaException: No View Model registered for View 'MyModule:EComWidget:Categories'. Check that you have registered this View in the 'MyModule' area registration.
   at Sdl.Web.Common.Models.ModelTypeRegistry.GetViewModelType(MvcData viewData)
   at Sdl.Web.Tridion.Mapping.DefaultModelBuilder.BuildEntityModel(EntityModel& entityModel, IComponentPresentation cp, Localization localization)
   at Sdl.Web.Tridion.Mapping.ModelBuilderPipeline.CreateEntityModel(IComponentPresentation cp, Localization localization)
   at Sdl.Web.Tridion.Mapping.DefaultModelBuilder.BuildPageModel(PageModel& pageModel, IPage page, IEnumerable`1 includes, Localization localization)
2016-12-13 15:43:00,298 [5] ERROR - The model item passed into the dictionary is of type 'Sdl.Web.Common.Models.ExceptionEntity', but this dictionary requires a model item of type 'Sdl.Web.Common.Models.PageModel'.
System.InvalidOperationException: The model item passed into the dictionary is of type 'Sdl.Web.Common.Models.ExceptionEntity', but this dictionary requires a model item of type 'Sdl.Web.Common.Models.PageModel'.
   at System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value)
   at System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary)
   at System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData)
   at System.Web.Mvc.WebViewPage.ConfigurePage(WebPageBase parentPage)
   at System.Web.WebPages.WebPageBase.<>c__DisplayClass3.<RenderPageCore>b__2(TextWriter writer)
   at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)
   at System.Web.WebPages.WebPageBase.Write(HelperResult result)
   at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)
   at System.Web.WebPages.WebPageBase.PopContext()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at RazorGenerator.Mvc.PrecompiledMvcView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
2016-12-13 15:43:00,414 [5] ERROR - Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.
System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'. ---> System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Web.Mvc.HandleErrorInfo', but this dictionary requires a model item of type 'Sdl.Web.Common.Models.PageModel'.
   at System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value)
   at System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary)
   at System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData)
   at System.Web.Mvc.WebViewPage.ConfigurePage(WebPageBase parentPage)
   at System.Web.WebPages.WebPageBase.<>c__DisplayClass3.<RenderPageCore>b__2(TextWriter writer)
   at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)
   at System.Web.WebPages.WebPageBase.Write(HelperResult result)
   at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)
   at System.Web.WebPages.WebPageBase.PopContext()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at RazorGenerator.Mvc.PrecompiledMvcView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerAsyncWrapper.<>c__DisplayClassa.<EndProcessRequest>b__9()
   at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.<>c__DisplayClass4.<Wrap>b__3()
   at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func`1 func)
   at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap(Action action)
   at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerAsyncWrapper.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
   at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
   at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage)
   at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)
   at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)
   at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter)
   at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues)
   at Sdl.Web.Mvc.Html.HtmlHelperExtensions.DxaEntity(HtmlHelper htmlHelper, EntityModel entity, Int32 containerSize) in C:\Users\l19548828\SourceCode\dxa-web-application-dotnet\Sdl.Web.Mvc\Html\HtmlHelperExtensions.cs:line 297
   at Sdl.Web.Mvc.Html.HtmlHelperExtensions.DxaEntities(HtmlHelper htmlHelper, Int32 containerSize) in C:\Users\l19548828\SourceCode\dxa-web-application-dotnet\Sdl.Web.Mvc\Html\HtmlHelperExtensions.cs:line 352
   at ASP._Areas_MyModule_Views_Region_Main_cshtml.Execute() in C:\Users\l19548828\SourceCode\my.web\Modules\My.Web.MyModule\obj\CodeGen\Areas\MyModule\Areas\MyModule\Views\Region\Main.cshtml:line 3
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at RazorGenerator.Mvc.PrecompiledMvcView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)

from dxa-web-application-dotnet.

jhorsman avatar jhorsman commented on July 19, 2024

After some more debugging we found what's causing this error in our implementation. The cause is twofold:

  1. User error; we used a Views\_ViewStart.cshtml in our web application project.
  2. DXA makes an not so intuitive assumption; DXA assumes the web application does not use a Views\_ViewStart.cshtml while this is common to have one in a .NET MVC site.

We fixed this by removing the Views/_ViewStart.cshtml from our site project, but I would still like to propose an improvement to prevent others running into the same issue.

DXA assumes there is no Views\_ViewStart.cshtml. The example Site project also does not have one. Instead, the ViewStart is in Views\Areas\Core\Views\Page.

If you do happen to put Views\_ViewStart.cshtml in your project, and an excption occurs. DXA will:

  1. load the EntityError.cshtml, SectionError.cshtml or Server.cshtml
  2. those in turn will try to load the ViewStart
  3. which in turn directs to the _Layout.cshtml which tries to use a page model which is not set.

In the log posted in an earlier comment you can see that something goes wrong with the view model mapping. What happens is that

  1. an ExeptionEnitity is loaded into the region model
  2. the entity view is rendered in the region view
  3. the entity view uses the ViewStart and the _Layout.cshtml which will raise an exception because it is expecting a PageModel instead of a ExecptionEntity.

I propose the following changes to DXA:

  1. Use PartialViewResult instead of ViewResult in HandleSectionErrorAttribute.cs. This will prevent the SectionError.cshtml and Server.cshtml` to load the ViewStart at all.
  2. Add @{ Layout = ""; } to the ServerError.cshtml so that it will not use Layout configured in the ViewStart.
  3. If (1) is not practical for reasons I don't foresee: add @{ Layout = ""; } to SectionError.cshtml and Server.cshtml` as well.

from dxa-web-application-dotnet.

rpannekoek avatar rpannekoek commented on July 19, 2024

Internal Issue ID (for tracking purposes): CRQ-12795

from dxa-web-application-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.