title: ASP.NET Core 3.1 web application throws error 500.30 when run on IIS Express, but not when using dotnet watch run
body: <p>When running my application from Visual Studio 2019 on IIS Express the web page gives error 500.30 and in the output it says,</p>
  
  <pre><code>Exception thrown: 'System.NullReferenceException' in System.Private.CoreLib.dll
  </code></pre>
  
  <p>However, when running it in a terminal using <code>dotnet watch run</code> the page runs without errors and displays correctly. </p>
  
  <p>I've tried running the debugger and the error is always thrown on this line,</p>
  
  <pre><code>CreateHostBuilder(args).Build().Run();
  </code></pre>
  
  <p>after my ConfigureSerives Method below completes</p>
  
  <pre><code>// This method gets called by the runtime. Use this method to add services to the container.
          public static void ConfigureServices(IServiceCollection services)
          {
              services.AddControllers();
              services.AddRouting();
          }
  </code></pre>
  
  <p>I've also tried repairing my Visual Studio 2019 as well as reinstalling .NET 3.1.100 SDK with no luck.</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>Edit:</p>
  
  <p>I had to publish the program and then run the .exe, but this was the output I got</p>
  
  <pre><code>crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
        Application startup exception
  System.IO.DirectoryNotFoundException: C:\Users\ray.kochenderfer\Documents\public\hub\public\
     at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
     at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
     at QualityHub.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\ray.kochenderfer\repos\quality_hub\Startup.cs:line 49
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
     at Microsoft.AspNetCore.Hosting.ConfigureBuilder.&lt;&gt;c__DisplayClass4_0.&lt;Build&gt;b__0(IApplicationBuilder builder)
     at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.&lt;&gt;c__DisplayClass13_0.&lt;UseStartup&gt;b__2(IApplicationBuilder app)
     at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.&lt;&gt;c__DisplayClass0_0.&lt;Configure&gt;g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
     at Microsoft.AspNetCore.HostFilteringStartupFilter.&lt;&gt;c__DisplayClass0_0.&lt;Configure&gt;b__0(IApplicationBuilder app)
     at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
  Unhandled exception. System.IO.DirectoryNotFoundException: C:\Users\ray.kochenderfer\Documents\public\hub\public\
     at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
     at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
     at QualityHub.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\ray.kochenderfer\repos\quality_hub\Startup.cs:line 49
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
     at Microsoft.AspNetCore.Hosting.ConfigureBuilder.&lt;&gt;c__DisplayClass4_0.&lt;Build&gt;b__0(IApplicationBuilder builder)
     at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.&lt;&gt;c__DisplayClass13_0.&lt;UseStartup&gt;b__2(IApplicationBuilder app)
     at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.&lt;&gt;c__DisplayClass0_0.&lt;Configure&gt;g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
     at Microsoft.AspNetCore.HostFilteringStartupFilter.&lt;&gt;c__DisplayClass0_0.&lt;Configure&gt;b__0(IApplicationBuilder app)
     at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
     at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
     at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
     at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
     at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
     at QualityHub.Program.Main(String[] args) in C:\Users\ray.kochenderfer\repos\quality_hub\Program.cs:line 16
  </code></pre>