title: ASP.Net Core - Unexpected exception in IISHttpServer.HandleRequest
body: <p>I have <code>ASP.Net Core 2.2</code> application. This is running fine when running from Visual Studio (Both Debug &amp; Release mode)</p>
  
  <p>But when I deploy the same to IIS in any machine, it's throwing 500 error.</p>
  
  <blockquote>
    <p>"MessageTemplate": "Unexpected exception in
    IISHttpServer.HandleRequest.",
        "Exception": "System.NullReferenceException: Object reference not set to an instance of an object.\r\n   at
    Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.GetOriginalPath()\r\n
    at
    Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.InitializeContext()\r\n
    at
    Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()\r\n
    at
    Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer.HandleRequest(IISHttpContext
    context)",
        "Properties": {
            "SourceContext": "Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer"
        }</p>
  </blockquote>
  
  <p>On Googling, the only link:</p>
  
  <p><a href="https://github.com/aspnet/AspNetCore/issues/6075" rel="nofollow noreferrer">https://github.com/aspnet/AspNetCore/issues/6075</a></p>
  
  <p><a href="https://i.stack.imgur.com/VpY83.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VpY83.png" alt="Application Initilization "></a></p>
  
  <p>Note I am running the app in IIS, with <code>StartMode</code> set to <code>OnDemand</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/ySMPR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ySMPR.png" alt="Preload Settings in IIS"></a></p>
  
  <p>What's causing this error &amp; how to get rid of this?
  Thanks!</p>