ASP.NET Core 3.1 web application throws error 500.30 when run on IIS Express, but not when using dotnet watch run

10,826

Solution 1

There is github issue about this problem.

Using 2.x versions of Microsoft.Extensions.* and Microsoft.AspNetCore.* packages in an ASP.NET Core 3.0/3.1 project is *not supported.

In my case i was depending on nuget package which was depending on Microsoft.AspNetCore 2.x.x. After removing the nuget the project ran without issues under IIS Express.

If anyone is still having this issue, you can try to remove dependencies with version 2.x because they are automatically resolved from the SDK.

Solution 2

I had the same problem with IISExpress. The only way I could get ride of the 500.30 error, was to run the application in OutOfProcess mode.

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
  </PropertyGroup>

Solution 3

This can be due to any number of reasons and without logging, it will be very difficult to determine what's going on.

Add a web.config with similar configuration. stdoutLogEnabled will generate logs that can help further troubleshoot the issue, especially if it's specific to IIS Express.

<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet"
                  arguments=".\MyApp.dll"
                  stdoutLogEnabled="false"
                  stdoutLogFile=".\logs\stdout"
                  hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.1

Solution 4

I solved this issue. The issue had something to do with ASP.NET Core Version 2.2.0 interacting with Visual Studio 2019 Version 16.4.1. I Downgraded ASP.NET Core to Version 2.1.7 then updated it back to Version 2.2.0. This seems to have fixed the issue.

Edit: This only temporarily fixed the issue. However, downgrading to 2.1.7 seems to be working reliably.

Share:
10,826
Ray Kochenderfer
Author by

Ray Kochenderfer

Updated on June 09, 2022

Comments

  • Ray Kochenderfer
    Ray Kochenderfer about 2 years

    When running my application from Visual Studio 2019 on IIS Express the web page gives error 500.30 and in the output it says,

    Exception thrown: 'System.NullReferenceException' in System.Private.CoreLib.dll
    

    However, when running it in a terminal using dotnet watch run the page runs without errors and displays correctly.

    I've tried running the debugger and the error is always thrown on this line,

    CreateHostBuilder(args).Build().Run();
    

    after my ConfigureSerives Method below completes

    // 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();
            }
    

    I've also tried repairing my Visual Studio 2019 as well as reinstalling .NET 3.1.100 SDK with no luck.

    Any help would be greatly appreciated!

    Edit:

    I had to publish the program and then run the .exe, but this was the output I got

    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.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
       at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__2(IApplicationBuilder app)
       at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
       at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>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.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
       at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__2(IApplicationBuilder app)
       at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
       at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>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