Search code examples
c#windows-10iis-expressasp.net-core-3.1.net-core-3.1

Windows 10 Visual Studio 2019 IIS Express won't start with error 500


We have an API project in .Net Core 3.1. It is working in all the computers in the team but when tried to debug it on a new member computer it failed. It states there is a server error (500) and won't start the program. It works as a local service, without IIS.

VS Error Event Log Error

We have tried to format the computer and start fresh, with no use. I saw posts relating to the project configurations and launch settings, but since it is working on other machines I don't think this is the issue. We also tried to add the required lines for the aspnetcore modules in iis template files and the dlls as seen in other places where it was recommended, getting the same issue.

Any suggestion will be appreciated!


Error text from your HttpFailure_08-24-17.tml file

NOTE: you really should have copied/pasted as text, instead of a attaching a screen shot:

The description for Event ID 1034 from source IIS Express AspNetCore Module V2 cannot found.  
Either the component that raises this event is not installed on your local computer or the installation is corrupted. 
You can install or repair the component on the local computer.
... 
The following information was included with the event:

Could not load configuration. Exception message: Unable to get required configuration section 'system.webServer/aspNetCore'.  Possible reason is web.config authoring error.

The request is not supported.

EDIT: Program.cs:

 public class Program
{
    public static void Main(string[] args)
    {
        try
        {
            Console.Error.WriteLine("Starting application (from error log without errors)");

            var config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build();

            Console.WriteLine("Config set");

            var hostBuilder = new WebHostBuilder()
                .UseKestrel(opt => opt.AddServerHeader = false)
                .UseConfiguration(config)
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>();

            Console.WriteLine("hostBuilder set");

            // ConfigureServices is only used to delay execution until UseIISIntegration()
            // has actually set the "urls" setting.

            Console.WriteLine("urls for hostBuilder " + hostBuilder.GetSetting("urls"));

            hostBuilder.ConfigureServices(services =>
            {
                var urls = hostBuilder.GetSetting("urls");
                urls = string.IsNullOrWhiteSpace(urls) ? "127.0.0.1" : urls.Replace("localhost", "127.0.0.1");
                hostBuilder.UseSetting("urls", urls);
            });

            Console.WriteLine("hostBuilder.ConfigureServices set");

            var host = hostBuilder.Build();

            Console.WriteLine("host set");

            host.Run();

        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex.Message);
        }
    }
}

Solution

  • The error is warning you about AspNetCore Module V2 being corrupt or missing.

    There is a module required to be installed in IIS to be compatible with AspNetCore projects (in particular, working with the default Kestrel server).

    You need to follow these instructions and install this module. As far as I can recall, it does not require any additional configuration.

    EDIT:

    I stumbled upon this article, which refers that they also had issues with IIS Express. Maybe it can be of help to you, and follow their guide to find what is wrong in your configuration?

    https://blog.maartenballiauw.be/post/2019/02/26/asp-net-core-iis-express-empty-error-starting-application.html