Solving exceptions in ASP.NET Core exceptions when the _Layout.cshtml file fails processing
Posted: (EET/GMT+2)
ASP.NET Core applications are usually very easy to debug, thanks for extensive information provided in the development mode default exception error page/view. However, especially when there are low-level exceptions when processing your _Layout.cshtml file, you might end up in a situation where your web application simply responds with a "HTTP 500 Internal Server Error" message, but without any payload (body content). When this happens, the real reason for the error can be tricky to find, as no error messages are displayed.
If you suspect this is the situation, you might want to edit the default error view file in "Views\Shared\Error.cshtml" so that at the beginning of the file, the layout file is set to null. This skips the using of the potentially faulty layout file, and just dumps the contents to the browser.
Now, the static default Error file isn't very useful in debugging, but you can replace it with more meaningful content. Also, you can enable detailed exception display, when you enabled the development mode. For more details, see the hosting section on the new ASP.NET documentation portal.
PS. Quick tip on Application Insights: in case the above solution fails to give you enough information, try enabling Application Insights in your project, and then deploy.