Whenever an error occurs in my application, I'm not able to view the correct error in the event viewer. In it's place I get the following error...
The model item passed into the dictionary is of type 'System.Web.Mvc.HandleErrorInfo', but this dictionary requires a model item of type 'LayoutPageViewModel'
I get why this error occurs (because the controller is trying to pass a model of type HandleErrorInfo to the original view) but what I can't figure out is how stop this error showing up in the event viewer and show the real error.
So the sequence of events are:
- Exception occurs in the application
- Default error handling tries to pass model of type 'System.Web.Mvc.HandleErrorInfo' into default layout page, which accepts a model of 'LayoutPageViewModel'
- Another exception occurs in the application because the layout is being passed a model of type 'HandleErrorInfo'
The custom error 500 page (specified in the web.config) is hit, which doesn't reference any layout:
@{ Layout = null; }
Error page is shown correctly but the exception in the event viewer is incorrect.
I have tried setting the master and view for the HandleErrorAttribute filter in Application_Start but that stops anything being registered in the event logs. I've also tried adding the following method to the controller...
protected override void OnException(ExceptionContext filterContext)
{
filterContext.Result = new ViewResult {
ViewName = "~/Views/Shared/Error.cshtml",
};
}
but that has the same result as the HandleErrorAttribute workaround.
Does anyone have an idea of how I can get around this problem?