3

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);
        }
    }
}
Dani Toker
  • 406
  • 6
  • 19
  • 1
    Please start your app in MSVS, reproduce the HTTP 500 error, and carefully look through the MSVS "Output" window for any error messages and/or stack traceback. Please update your post. – FoggyDay Jun 03 '20 at 05:09
  • @FoggyDay I only get 404 which is to be expected. Added in the post what I get when running IIS Express (VS Error and event log) – Dani Toker Jun 03 '20 at 05:46
  • 1
    Typically, running "MSVS > Debug" of your project's app will *START* IIS Express, will bring up a browser window ... and will show all runtime messages (including errors) in the MSVS Output window. It sounds like you're doing "something different". – FoggyDay Jun 03 '20 at 05:51
  • Does this answer your question? [My ASP.NET Core app says it can't read web.config](https://stackoverflow.com/questions/52102413/my-asp-net-core-app-says-it-cant-read-web-config) – FoggyDay Jun 03 '20 at 06:01
  • We have tried what is suggested there, didn't work – Dani Toker Jun 03 '20 at 06:14
  • This is the non-iis launch settings: { "commandName": "Project", "launchBrowser": true, "launchUrl": "http://localhost:5000/api/values", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } – Dani Toker Jun 03 '20 at 06:15
  • Could you edit the question and paste in your `Program.cs` and `Startup.cs` contents? – Sotiris Panopoulos Jun 03 '20 at 06:28
  • 1
    Have you seen this article? I had no idea this worked that way, maybe it fits your case: https://blog.maartenballiauw.be/post/2019/02/26/asp-net-core-iis-express-empty-error-starting-application.html – Sotiris Panopoulos Jun 03 '20 at 06:29
  • I'm wondering ... Q: Are you running MS Visual Studio (the full IDE) ... or "Visual Studio Code"? That would make a difference ;() – FoggyDay Jun 03 '20 at 06:32
  • The error message has "Microsoft Visual Studio" as a title – Sotiris Panopoulos Jun 03 '20 at 06:32
  • @Sotiris Koukios-Panopoulos - I'm no longer sure that title is accurate ;) If the OP was truly using the MSVS IDE, everything should "just work". – FoggyDay Jun 03 '20 at 06:34
  • I would agree, then I saw the article I mentioned above, which had the exact problem. IIS Express wouldn't "just work" – Sotiris Panopoulos Jun 03 '20 at 06:36
  • I'm using visual studio professional 19 – Dani Toker Jun 03 '20 at 06:55
  • Next time make sure you post the content of `web.config`, as that error message indicates so. – Lex Li Jun 03 '20 at 13:27

2 Answers2

1

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

Sotiris Panopoulos
  • 1,523
  • 1
  • 13
  • 18
0

Seems like we have an Antivirus causing errors in Visual Studio 2019 install, disrupting the netcoreapp.dll and others. I'm closing this stating that after antivirus was shut down and install went forward, the blog post @Sotiris Koukios-Panopoulos did the trick.

Dani Toker
  • 406
  • 6
  • 19