{"action":"created","issue":{"url":"https://api.github.com/repos/NancyFx/Nancy/issues/2122","labels_url":"https://api.github.com/repos/NancyFx/Nancy/issues/2122/labels{/name}","comments_url":"https://api.github.com/repos/NancyFx/Nancy/issues/2122/comments","events_url":"https://api.github.com/repos/NancyFx/Nancy/issues/2122/events","html_url":"https://github.com/NancyFx/Nancy/issues/2122","id":118129564,"number":2122,"title":"Unable to cast object of type 'DefaultStatusCodeHandlerResult' to Model type","user":{"login":"xori","id":1091220,"avatar_url":"https://avatars.githubusercontent.com/u/1091220?v=3","gravatar_id":"","url":"https://api.github.com/users/xori","html_url":"https://github.com/xori","followers_url":"https://api.github.com/users/xori/followers","following_url":"https://api.github.com/users/xori/following{/other_user}","gists_url":"https://api.github.com/users/xori/gists{/gist_id}","starred_url":"https://api.github.com/users/xori/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xori/subscriptions","organizations_url":"https://api.github.com/users/xori/orgs","repos_url":"https://api.github.com/users/xori/repos","events_url":"https://api.github.com/users/xori/events{/privacy}","received_events_url":"https://api.github.com/users/xori/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NancyFx/Nancy/labels/Bug","name":"Bug","color":"ff0000"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/NancyFx/Nancy/milestones/38","html_url":"https://github.com/NancyFx/Nancy/milestones/2.0","labels_url":"https://api.github.com/repos/NancyFx/Nancy/milestones/38/labels","id":965127,"number":38,"title":"2.0","description":"Authentication update to use the (horrible) .net 4.5 style ClaimsPrincipal.","creator":{"login":"grumpydev","id":527013,"avatar_url":"https://avatars.githubusercontent.com/u/527013?v=3","gravatar_id":"","url":"https://api.github.com/users/grumpydev","html_url":"https://github.com/grumpydev","followers_url":"https://api.github.com/users/grumpydev/followers","following_url":"https://api.github.com/users/grumpydev/following{/other_user}","gists_url":"https://api.github.com/users/grumpydev/gists{/gist_id}","starred_url":"https://api.github.com/users/grumpydev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grumpydev/subscriptions","organizations_url":"https://api.github.com/users/grumpydev/orgs","repos_url":"https://api.github.com/users/grumpydev/repos","events_url":"https://api.github.com/users/grumpydev/events{/privacy}","received_events_url":"https://api.github.com/users/grumpydev/received_events","type":"User","site_admin":false},"open_issues":26,"closed_issues":31,"state":"open","created_at":"2015-02-04T09:08:48Z","updated_at":"2015-12-02T22:13:11Z","due_on":null,"closed_at":null},"comments":18,"created_at":"2015-11-20T21:28:10Z","updated_at":"2015-12-03T16:32:49Z","closed_at":null,"body":"This is a very weird bug that I've come across, and the most frustrating part is that 30% of the time it doesn't come up.\r\n\r\n#### The Error\r\n```\r\nServer Error in '/' Application.\r\nUnable to cast object of type 'DefaultStatusCodeHandlerResult' to type 'My.ModelType'.\r\n\r\n[InvalidCastException: Unable to cast object of type 'DefaultStatusCodeHandlerResult' to type 'My.ModelType'.]\r\n   Nancy.ViewEngines.Razor.NancyRazorViewBase`1.Initialize(RazorViewEngine engine, IRenderContext renderContext, Object model) +50\r\n...\r\n```\r\n\r\n#### The Module\r\n```c#\r\nGet[\"/{transaction}\"] = param => {\r\n    var model = new EFDatabase().Transactions.Single(param.transaction);\r\n    return Negotiate\r\n        .WithView(\"Purchase\")\r\n        .WithModel(model); // I have confirmed this is not null\r\n};\r\n```\r\n\r\n#### The View\r\n```c#\r\n@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<My.ModelType>\r\n...\r\n```\r\n\r\nIf I request the route `/transaction-id.json` I correctly get the JSON encoded string. But if I view the the route in the browser I get the ASP Error page (not the cute Nancy one) with the message listed above. Plus, the mentioned type `DefaultStatusCodeHandlerResult` is a Nancy error model to my understanding which leads me to believe that an error occurs (somewhere) and it tries to coerce that error to my specified View, rather than redirecting to the Nancy error page.\r\n\r\nSo my question is why am I getting this ASP error page, compared to a Nancy Error page? And what steps can I do to debug this? Google doesn't really have an answer to this `DefaultStatusCodeHandlerResult`"},"comment":{"url":"https://api.github.com/repos/NancyFx/Nancy/issues/comments/161707552","html_url":"https://github.com/NancyFx/Nancy/issues/2122#issuecomment-161707552","issue_url":"https://api.github.com/repos/NancyFx/Nancy/issues/2122","id":161707552,"user":{"login":"jonathanfoster","id":1923583,"avatar_url":"https://avatars.githubusercontent.com/u/1923583?v=3","gravatar_id":"","url":"https://api.github.com/users/jonathanfoster","html_url":"https://github.com/jonathanfoster","followers_url":"https://api.github.com/users/jonathanfoster/followers","following_url":"https://api.github.com/users/jonathanfoster/following{/other_user}","gists_url":"https://api.github.com/users/jonathanfoster/gists{/gist_id}","starred_url":"https://api.github.com/users/jonathanfoster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonathanfoster/subscriptions","organizations_url":"https://api.github.com/users/jonathanfoster/orgs","repos_url":"https://api.github.com/users/jonathanfoster/repos","events_url":"https://api.github.com/users/jonathanfoster/events{/privacy}","received_events_url":"https://api.github.com/users/jonathanfoster/received_events","type":"User","site_admin":false},"created_at":"2015-12-03T16:32:49Z","updated_at":"2015-12-03T16:32:49Z","body":"I submitted PR https://github.com/NancyFx/Nancy/pull/2140 to resolve this issue. You can reproduce it in https://github.com/jonathanfoster/nancy-demo-errorhandlerinvalidcastexception/."}}