48

I attempt to lunch my ASP.NET Core project in Microsoft Visual Studio 2019 and got this error: "Unable to connect to web server 'IIS Express'"

  • Visual Studio 2019 Version 16.9.5
  • .Net 5.0
5
  • 3
    I've had this issue multiple times. Usually, a restart will fix it, but you can also try to delete the bin, obj, and .vs folders from the project, then shut down the iis express service and try to run it again. I've sometimes ended up with creating a new project and copied all files over and that always works. Commented Aug 7, 2021 at 17:59
  • Just a tip: if you debug the app by hitting F5, you can usually see the details of error. E.g. if you mess with routing, the Kestrel shows you this error if you try to run with Ctrl+F5. So in my case it was nothing related to ports/web server/windows services, etc, but just some internal routing issues. Commented Oct 31, 2022 at 17:35
  • @SiavashMortazavi Kestrel shows error when using IIS Express? Commented Aug 3, 2023 at 7:52
  • @TheincredibleJan Kestrel is another web server, different from IIS Express. I meant you can use Kestrel to see if it's a routing error, then if it's not, switch to IIS Express. Commented Aug 24, 2023 at 17:19
  • restart does not fix the problem at all. If the messages disapperas, it is pure luck and a inprobable constellation of circumstances. Commented Sep 22 at 9:51

19 Answers 19

73

If rebooting fixes this for you, then do this instead:

net stop winnat net start winnat 

The problem is that something reserved your desired port and made it unavailable.

See https://superuser.com/a/1610009/239292

Sign up to request clarification or add additional context in comments.

6 Comments

worked for me, vs2022
Rebooting didn't fix this for me, but running these commands worked, thanks!
Worked for me :) VS22 / .NET 6 Web MVC
This works like a charm. I tried to change to many different ports which I believe none of them were used, but still no luck.
not for me and VS 2022
|
51

I tried this one and it worked for me:

  1. Go to 'Debug Properties'

  2. Find 'Web Server Settings'

  3. Change the port in 'App URL' section and save the changes

  4. Run the application and the same error will appear again

  5. Switch the port back to the original port and save the changes

  6. Run the application and enjoy it!

I hope this trick work for you.

6 Comments

In my case, the same error did not show up after changing App URL, but it worked! VS 2019 16.11.5
I simply changed the port and wrote some nonsense into it. Then I started the program, which of course didn't work. Then I corrected the port again by specifying the correct number. The next start was successful again! Excellent, thank you very much!
This answer worked in VS 2022, except that the error did not appear in step 4 and switching the port number back (step 5) caused the error to reappear. Therefore, it seems that steps 4 and 5 should be skipped in VS 2022.
"Go to 'Debug Properties'" I would love to know where.
@Parrotmaster In the IIS Server dropdown menu, you will find your project's Debug Properties at the end.
|
12

1- Go to 'Debug Properties', Find 'Web Server Settings', Change the port in 'App URL' section and save the changes

In your project folder, delete .vs file, also remove the launch settings file in properties (make sure you copy to a different folder before removing it).

Restart visual studio and your machine if possible. Go to launch setting, check if they are properly configured similar to your prev launch settings. Run the application in IIS.

Should start working.

1 Comment

There is no ".vs" file anywhere. This does not make any difference (of course, as nothing changed).
10

The following fixed the problem for me.

1 Comment

Delete the "properties\launchsettings.json" file. This cleared the error, but now I don't have the Swagger that relied on that file.
4

I encountered the same issue , but after few seconds i find out that there is a duplicated sslport , the same sslport being registered for another running app , so when i run another app with the same setting i see this error , you have to change the sslport in the launchsetting.json look the picture below

Comments

3

For those how are still trying.

It might be because your application is not starting up in the first place. These due to logic errors in the Program.cs or Startup.cs.

For me it was a Service that I didn't implement to Dependency Injection.

So the Solution for me was to add the Service builder.Services.AddTransistend(...).

3 Comments

Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?
This was my issue as well. I had some poorly written code and for some reason it wasn't caught and it chose that error. Pretty bizarre.
Finally, the actual solution! Thanks.
1

From my experience this issue appears when the port used is already in use by other process. You will see the following:
Error description: The process cannot access the file because it is being used by another process. (0x80070020)
Just choose a port number which is free to use and the problem will disappear!

Comments

0

To me it has worked by switching the project from Debug to Release and Starting it. When I switch back to Debug it starts correctly. It appears to me that For some reason i had the Release project running so the Debug couldn't start.

Comments

0

I have just an API project. Going to project's Properties\Debug and unchecking the 'Launch browser' helped.

Comments

0

In my case... (Visual Studio 2019, .net 5, blazor wasm project):

  • I did bkp copy of "Properties\launchSettings.json" file and ".vs" folder (just in case)
  • I deleted the "Properties\launchSettings.json" file and open the solution.. This file is recreated with default values...
  • After that, the error is gone and I was able to run and debug the application normally.

Now you can redo your updates on the "Properties\launchSettings.json" (i.e. change port).

Comments

0

In my case it was the wrong .net6 version. I work in a project with other developers. The main developer switched the project from .net5 to .net6. He has 6.0.3 installed, I have 6.0.2. Visual Studio did not show this. On the console with dotnet run, I get this error message.

Comments

0

My error message was regarding Kestrel web server: Visual Studio is unable to connect to web server... the web server is no longer running. I had to replace applicationUrl values from https://0.0.0.0:5001 to https://localhost:5001 . I got this error when I updated Visual Studio 2022 to 17.3.0

Comments

0

If you are like me and have probably tried all the above answers to no avail, here is a final solution that has helped me many times.

Answer: Do not restart your system (did this and it failed to work for me most times), rather, save all your work items, then shut down your system to allow all running process to shut down, then power on again.

If you do a restart, IIS Express may not get shut down completely, therefore, your port will still be used by the process holding on to it.

This works for me always

Comments

0

not sure if this answer will help anybody but I had made changes in appsettings.json file in Asp.net Core (net 6) and forgot to add coma after curly brackets

{ "AppSetting": { "Token": "MY TOKEN" }, ----------------------->here "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*" } 

Hence: you might find your errors in your warnings

Comments

0

In my case Enabling(Start-->Services-->WWW Pub.service) the WorldWideWeb Publishing Services resolves the issue of contacting remote server debugger

Comments

0

Well for me nothing worked of the above, and I tested everything. At the end what worked was a simple restart of the computer.

Environment:

  • Windows 11
  • Visual Studio 22
  • ASP.NET 6

Comments

0

For me Clean Solution and Rebild Solution fixed the problem.

Comments

0

In my case, I forgot to create the Hangfire Database.

Comments

-1

I had this problem, but I created it myself. I modified the app.Run(); by adding a bit of code in the middle of this method. The solution was simple, it was necessary to have a clean app method at the end app.Run();

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.