Visual studio 2019 “Unable to connect to web server 'IIS Express'”
Asked Answered
G

19

41

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
Gastrula answered 7/8, 2021 at 17:43 Comment(4)
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.Babineaux
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.Gagger
@SiavashMortazavi Kestrel shows error when using IIS Express?Rhetor
@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.Gagger
G
49

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.

Gastrula answered 7/8, 2021 at 17:57 Comment(4)
In my case, the same error did not show up after changing App URL, but it worked! VS 2019 16.11.5Coonan
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!Rese
Great, it also worked for me, thanksCreak
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.Chercherbourg
S
65

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

Standard answered 13/4, 2022 at 12:30 Comment(4)
worked for me, vs2022Marchese
Rebooting didn't fix this for me, but running these commands worked, thanks!Parthenogenesis
Worked for me :) VS22 / .NET 6 Web MVCDirac
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.Cloutman
G
49

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.

Gastrula answered 7/8, 2021 at 17:57 Comment(4)
In my case, the same error did not show up after changing App URL, but it worked! VS 2019 16.11.5Coonan
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!Rese
Great, it also worked for me, thanksCreak
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.Chercherbourg
Z
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.

Zach answered 7/10, 2021 at 9:48 Comment(0)
N
11

The following fixed the problem for me.

Nosebleed answered 8/10, 2021 at 5:20 Comment(1)
Delete the "properties\launchsettings.json" file. This cleared the error, but now I don't have the Swagger that relied on that file.Ken
H
5

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

Headrace answered 13/2, 2022 at 11:39 Comment(0)
M
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!

Machinery answered 19/10, 2021 at 20:46 Comment(0)
P
1

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(...).

Papyrology answered 20/12, 2023 at 13:36 Comment(1)
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?Middleclass
R
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.

Roadbed answered 19/1, 2022 at 10:36 Comment(0)
R
0

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

Raseta answered 1/2, 2022 at 13:29 Comment(0)
A
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).

Alligator answered 23/2, 2022 at 15:36 Comment(0)
P
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.

Prevocalic answered 23/3, 2022 at 8:19 Comment(0)
S
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

Somehow answered 16/8, 2022 at 10:36 Comment(0)
W
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

Wherefore answered 23/8, 2022 at 8:41 Comment(0)
F
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

Farleigh answered 25/8, 2022 at 20:28 Comment(0)
H
0

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

Haroun answered 23/2, 2023 at 9:8 Comment(0)
I
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
Imtiaz answered 7/4, 2023 at 8:32 Comment(0)
K
0

For me Clean Solution and Rebild Solution fixed the problem.

Keirakeiser answered 20/12, 2023 at 20:26 Comment(0)
L
0

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

Lackadaisical answered 31/12, 2023 at 0:33 Comment(0)
C
-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();

Cam answered 15/1, 2024 at 0:53 Comment(1)
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.Spoilsport

© 2022 - 2025 — McMap. All rights reserved.