.NET Core HTTP 500 (500.19) Internal Server error

How to resolve HTTP 500 Internal Server errors in ASP.NET Core

Posted by Bernard Lim on April 1, 2022

Background

Recently we encountered this issue where an ASP.NET Core Web App just did not want to load. It was a .NET Core 3.1 IIS hosted app.

On page load, all that was shown was a HTTP 500 Internal Server error. After binding to localhost in IIS, we thought we had a little better context on what was happening as it specifically shown HTTP 500.19 with HRESULT code 0x8007000d.

What To Check

  • Check Logs - Application, Windows Event Logs
    Check to see if there is anything that could give you a hint in the logs. Weirdly, we did not have any logs at all. Even from the Event Viewer!

  • Check Configuration file (web.config)
    According to the Microsoft Docs, this is because of malformed XML. We checked the config files on our app however it seems ok. The app also runs locally which means the config files are likely to be correct.
    MS Docs Screenshot

  • .NET Runtime
    Check if the correct .NET Runtime is installed by running dotnet --version via CMD

  • Re-installing the hosting bundles
    Try uninstalling and re-installing the hosting bundles multiple times. In our case we had older .NET Core 2.1 runtimes installed previously. We weren’t sure if it could be related, however sometimes it is best to start clean and only install what is required.

  • Restart
    Try the usual IIS reset via CMD:
    net stop was /y
    net start w3svc
  • Reboot Machine
    If all the above checks are passed and it does not work, there is no harm in even giving the server / machine a re-boot!

Ultimate Solution

Frustratingly, we did all the above but to no avail. Ultimately, we stumbled across an article saying something about ApplicationHost.config and the missing aspnetcore element.

The file can be found here: %WinDir%\System32\Inetsrv\Config\applicationHost.config
Ensure the following setting is present in the ApplicationHost.config file.

<section name="aspNetCore" overrideModeDefault="Allow" /> within <sectionGroup>

No idea why but somehow it was missing from ours. I assume this should be automatically done when installing the Hosting Bundle. However, this solved our problem.

Hope this helps.