Whenever an error occurs in my application, I cannot see the correct error in the event viewer. At this point, I get the following error ...
The model element passed to the dictionary is of type "System.Web.Mvc.HandleErrorInfo", but this dictionary requires a model element of type "LayoutPageViewModel"
I understand why this error occurs (because the controller is trying to pass a model like HandleErrorInfo to the original view), but I cannot figure out how to stop this error appearing in the event viewer and show the real error.
Thus, the sequence of events:
- An exception occurs in the application.
- The default error handling attempts to pass a model of type "System.Web.Mvc.HandleErrorInfo" to the default layout page, which accepts a model of "LayoutPageViewModel"
- Another exception is thrown in the application because the layout is passed by a model of type "HandleErrorInfo"
The page with a custom error 500 (specified in the web.config file) that does not reference any layout is deleted:
@{ Layout = null; }
The error page displays correctly, but the exception in the event viewer is incorrect.
I tried to install the wizard and view the HandleErrorAttribute filter in Application_Start, but this stops everything that is being logged in the event logs. I also tried adding the following controller to the controller ...
protected override void OnException(ExceptionContext filterContext) { filterContext.Result = new ViewResult { ViewName = "~/Views/Shared/Error.cshtml", }; }
but it has the same result as the HandleErrorAttribute workaround.
Does anyone have any idea how I can get around this problem?
source share