Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 645
Ray Kochenderfer Avatar asked Dec 16 '19 16:12

Ray Kochenderfer


People also ask

What is a 500 Internal Server Error?

This error occurs within the app's code during startup or while creating a response. The response may contain no content, or the response may appear as a 500 Internal Server Error in the browser. The Application Event Log usually states that the app started normally.

How to check if IIS Express is running or not?

You’ll also see the system tray application of IIS Express. Right-click on it and click “Show All Applications” to see your running Web Apps. If you encounter any problem while running the application, check your Windows Event Viewer ( eventvwr.exe) for the detailed logs! The full path to the applicationhost.config file.

How to troubleshoot on IIS?

Troubleshoot on IIS 1 Application Event Log (IIS) 2 Run the app at a command prompt 3 ASP.NET Core Module stdout log (IIS) 4 ASP.NET Core Module debug log (IIS) 5 Enable the Developer Exception Page 6 Obtain data from an app 7 Slow or hanging app (IIS) More ...

Can I run ASP NET Core from the command line on IIS?

But it was required to run an ASP.NET Core 3.1 Web project from the Command Line on IIS Express At first, I thought it was easy! But I stumbled in some places. To keep this article simple, I don’t want to write all my tries. Here’s how you can start an ASP.NET Core 3.1 Web Project from the Command Line


3 Answers

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>
like image 146
Wingsche Avatar answered Oct 09 '22 06:10

Wingsche


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.

like image 4
vasil oreshenski Avatar answered Oct 09 '22 04:10

vasil oreshenski


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://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.1

like image 1
Mehdi Ibrahim Avatar answered Oct 09 '22 05:10

Mehdi Ibrahim