32

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
  • 2
    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. – SteinTheRuler Aug 07 '21 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. – Siavash Mortazavi Oct 31 '22 at 17:35
  • @SiavashMortazavi Kestrel shows error when using IIS Express? – The incredible Jan Aug 03 '23 at 07: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. – Siavash Mortazavi Aug 24 '23 at 17:19

15 Answers15

46

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.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • 2
    In my case, the same error did not show up after changing *App URL*, but it worked! VS 2019 16.11.5 – jvbs Nov 16 '21 at 20:30
  • 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! – peter70 Feb 25 '22 at 05:50
  • Great, it also worked for me, thanks – Ali Mumtaz May 24 '22 at 07:43
  • 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. – Mike Grove aka Theophilus Jun 01 '22 at 14:08
36

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

Rafe
  • 8,467
  • 8
  • 47
  • 67
11

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.

Hlobile S
  • 111
  • 1
  • 4
11

The following fixed the problem for me.

Pradeep Singh
  • 111
  • 1
  • 5
  • 1
    *Delete the "properties\launchsettings.json" file.* This cleared the error, but now I don't have the Swagger that relied on that file. – Super Jade Aug 20 '22 at 17:47
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

Dark Storm
  • 187
  • 4
  • 10
2

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!

Lemraj
  • 279
  • 3
  • 4
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.

0

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

Peter
  • 324
  • 4
  • 7
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).

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.

Eugen Spinne
  • 83
  • 1
  • 4
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

xhafan
  • 2,140
  • 1
  • 26
  • 26
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

Chidi-Nwaneto
  • 634
  • 7
  • 11
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

0

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

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
Michalis
  • 1
  • 4