48

I am using Microsoft Visual Studio 2019 Community preview, version 16.4.0 Preview 1.0. I just update to Windows 10 Pro Version 1903 OS build 18362.418 . With ASP.NET Core 3 web-app project (Blazor Server), When I press F5, I catch error

I can go to https://localhost:44333/ manually, but it is inconvenient. When I stop debug, I also turn off it manually at taskbar.

With another web-app project, the problem is not happen.

When I choose or not choose option Enable native code debugging, not success.

How to fix it?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • Do you just want to attach to the process? Then possible duplicate of https://stackoverflow.com/a/49297776/1260204 (".. you will have to attach "dotnet.exe" process in Visual Studio") – Igor Oct 11 '19 at 18:29
  • Does this answer your question? [Unable to launch the IIS Express Web server](https://stackoverflow.com/questions/15873126/unable-to-launch-the-iis-express-web-server) – Michael Freidgeim Jul 15 '21 at 01:34

20 Answers20

55

Enable/disable SSL

This is the easy fix. For me, toggling the "Enable SSL" setting in the project Debug tab inside Visual Studio (just change it to the opposite of what is currently set and run the project) has fixed the issue.

As I understand it, there are two reason this might work. First it causes Visual Studio to update the Applicationhost Config (more about that later). Secondly, sometimes the SSL address is bound. Therefore disabling SSL disables the problem.

Applicationhost Config

Open your $(solutionDir)\.vs\config\applicationhost.config file and ensure your site looks like this:

<site name="[YOUR PROJECT NAME]" id="3">
  <application path="/" applicationPool="Clr4IntegratedAppPool">
    <virtualDirectory path="/" physicalPath="//PATH/TO/YOUR PROJECT" />
  </application>
  <bindings>
    <binding protocol="http" bindingInformation="*:[YOUR_PORT]:localhost" />
    <binding protocol="https" bindingInformation="*:[YOUR_SSL_PORT]:localhost" />
  </bindings>
</site>

Make sure iplisten is configured to 0.0.0.0

If the IP listen list is not configured, this issue may occur (caution, I have no idea why).

Check netsh to ensure there is an entry for 0.0.0.0

PS C:\Windows\system32> netsh http show iplisten

IP addresses present in the IP listen list:
-------------------------------------------

::     
0.0.0.0

PS C:\Windows\system32>

Add the correct netsh rule if it does not exists. You'll need an admin cmd.exe or admin PowerShell for this.

PS C:\Windows\system32> netsh http add iplisten ipaddress=0.0.0.0

Ensure nothing is binding to the address you are using

This seems to be an issue with Blazor for me. If an address is binded to the address Blazor is trying to use, this can cause issues. Use netsh again to check what is in use.

netsh http show urlacl

An entry that looks like this

Reserved URL            : http://*:50902/
    User: \Everyone
    Listen: Yes
    Delegate: No
    SDDL: D:(A;;GX;;;WD)

Can be deleted with this command

netsh http del urlacl url=http://*:50902/
Joshcodes
  • 8,513
  • 5
  • 40
  • 47
  • 3
    Thanks, I recently upgraded to Win 10 Pro and that was when message "Unable to connect to web server 'IIS Express'" started to show. Running `netsh http add iplisten ipaddress=0.0.0.0` solved it for me. – Tomáš Apr 01 '20 at 12:59
  • 3
    Spent 5 hours on this, that one line did it for me netsh http add iplisten ipaddress=0.0.0.0. Thank you – C.Ikongo Dec 12 '20 at 21:15
  • 1
    Toggling SSL off fixed it for me. Thanks! – Karel Křesťan Feb 24 '21 at 11:57
  • 4
    `$ netsh int ipv4 show dynamicport tcp`, On my machine that's starting from port 49152. So make sure your project doesn't use ports above that number. – Jeremy Lakeman Feb 26 '21 at 05:36
  • 1
    Cycling the "enable SSL" worked for me. Thanks! – SuperJMN Mar 09 '21 at 16:42
38

I had the very same issue what OP described, I mean I got the error message, but checking the IIS Express icon, it was shown everything is OK, so manually going to the url was working.

Tried literally everything what is described above including

  • Stop the site within IIS Express
  • Stop IIS Express
  • Exit VS restart VS
  • Check everything in the .vs folder
  • Delete the .vs folder
  • as a POC created a brand new ASP.NET Core project, that worked properly

Nothing helped.

I know it is ridiculous as "solution", but after spending a half hour with this I finally restarted my machine and everything is working since then... Worth a try

g.pickardou
  • 32,346
  • 36
  • 123
  • 268
  • 2
    Restarting works but the problem is this error sometimes happen right after a restart. It's weird, for me it happens a lot in some solutions but not others. – Trinidad Jun 27 '20 at 07:44
  • 2
    tried a lot of these other solutions... only thing that worked was to close SLN, Delete the .vs folder, reopen solution. – Craig Aug 16 '20 at 18:46
  • 3
    Closing the solution, ditching the .vs folder and recycling IIS Express did the trick for me. – Ev Conrad Nov 12 '20 at 07:37
  • This has worked for me a couple different times now – ActualRandy Mar 30 '21 at 19:25
  • @EvConrad, after revisting this and other threads multiple times and trying everything, your solution worked for me. I even kept the old applicaitonhost.config from the .vs folder to see what difference a freshly generated file might contain. The only difference was the encoding of the .config file (UTF8 vs UTF8 w/BOM) and some leading whitespace before the row with the tag I had problems with. – Dan Gøran Lunde May 23 '22 at 12:46
  • The next day, the problem reappears. And now it does not help deleting the .vs folder. – Dan Gøran Lunde May 24 '22 at 10:08
  • This always seem to be the case for me. A simple machine restart, after a lot of tweaks has been done and undone. I come here to meet this same answer to jump start my brain... lol – Prince Tegaton Nov 23 '22 at 11:42
  • Actually, the so-called "ridiculous" solution is the only one that works for me. – herve May 25 '23 at 07:12
23

Thought I would throw in what worked for me even though I'm late to the party. The solutions above didn't work for me.

  1. Went to the properties of the project -> Debug Tab
  2. Changed the port number in the AppURL to x + 1, i.e. for my instance http://localhost:44348 => http://localhost:44349
  3. Closed the solution
  4. Deleted the applicationhost config
  5. Reopened solution.
  6. Changed the port number back to the original

Voila

Mike Brunner
  • 402
  • 3
  • 11
broguyman
  • 1,386
  • 4
  • 19
  • 36
11

Removing .vs folder will solve this issue.

  1. Go to application location
  2. Remove .vs folder(hidden folder)
  3. Start project again!
Biju Maharjan
  • 389
  • 2
  • 9
9

I have had this problem occasionally in the past. I can often resolve the problem by:

  1. Click on show hidden icon area of task bar. You'll see an IIS Express icon.
  2. Select the icon and you should see your website listed. Drill down in that menu click "Stop site".

On other occasions I have had corporate security software interfere with Visual Studio/IIS Express operations. Usually you can get around the issue by running Visual Studio as Administrator. I've attempt explain to the security guys what an awful idea that is but usually they do not understand.

Finally, if you are running a Asp.Net Core application you can just give up on IIS Express. If you look next to the play button, there is a drop list that says "IIS Express". If you open the list you'll see your application's name there. Select that one. You'll be running using kestrel instead of IIS Express.

GlennSills
  • 3,977
  • 26
  • 28
  • 1
    Stop site worked for me. The only minor change to number 2 above is that you right click on the icon to see your site. – Mifo Sep 03 '20 at 13:39
  • Yeah, I think I could shorten it to "friends don't let friends use IIS Express" – GlennSills May 05 '23 at 14:43
9

Nothing worked for me (including deleting .vs, deleting obj and bin, cleaning the projects, restarting VS Studio, running netstat -ao | findstr <port number> to find out who is using my port and so on). Nothing.

Nothing except this:

  1. Open PowerShell as an administrator
  2. Run Get-Process -Id (Get-NetTCPConnection -LocalPort MY-PORT-NUMBER).OwningProcess (change port number to your port number)
  3. Finally, in my case, this showed that this process: service host: windows push notifications system service is using my port. Note the ID of this process and..
  4. Go to Task Manager (more details) > Processes > find the process by that ID and kill the child process (because this parent process itself can't be killed without the system becoming unusable)

That's it. It was windows push notifications system service in my case. Once I found it and killed it - everything is working without having to restart the whole computer or changing the port number.

Ivan Sivak
  • 7,178
  • 3
  • 36
  • 42
  • Why not just change the port number instead of killing a child process which you don't know if it's important to the system or not. – Tony_Henrich Aug 06 '22 at 02:43
  • @Tony_Henrich I could ask the same question the system that decided to steal my port after long time of using it and developing my web server app :) – Ivan Sivak Aug 07 '22 at 05:35
  • The system is free to use any free port. It doesn't keep track of what ports all the apps were using in the past and makes a decision about not using them ever. – Tony_Henrich Aug 08 '22 at 16:27
  • 1
    I get it, however, this happened to me in the middle of working on a distributed system with a bunch of microservices and for someone, it can be easier to just kill/restart the push notifications service than changing the port numbers or restarting the PC in the middle of dev session. – Ivan Sivak Sep 03 '22 at 12:19
  • 1
    @Tony_Henrich - Maybe the system should check to make sure the port is not already in use... js – Danimal111 May 04 '23 at 13:10
5

I had the same issue, I was able to solve it by changing the Port number.

  1. Right click on the project and select properties
  2. Go to the Debug section
  3. Under Web Server Settings change App URL port [just increase by one]
  • 3
    To shed some light why this may work is because this forces the regeneration of ".vs\PROJECTNAME\config\applicationhost.config". – Trinidad Jun 27 '20 at 08:02
  • 1
    you can use this to check for port availability as just incrementing by 1 might not work. `netsh interface ipv4 show excludedportrange tcp` and can delete them like this (sometimes) `netsh interface ipv4 delete excludedportrange tcp 4990 100` – LucidObscurity Feb 18 '21 at 01:39
5

I resolved this by closing Visual Studio (2019) and started it back up, running as Administrator.

Alex
  • 228
  • 4
  • 8
2

This works for me:

  1. Delete the "launchSettings.json" inside the "Properties" folder in the Project
  2. Open the project in Visual Studio
  3. Rebuild the project
  4. Debug (F5) or Run (Ctrl + F5).
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Abhishek
  • 41
  • 3
1

For me I had another application using the same port, I changed the port in project debug settings to something else.

Stuart Dobson
  • 3,001
  • 4
  • 35
  • 37
  • 1
    In my experience, this is the answer 100% of the time. I don't know why a certain port gets bugged, but changing ports has always solved it for me. – Bennyboy1973 Mar 09 '21 at 11:03
1

Changing the application url (by right clicking on the solution -> properties -> debug -> app url) from http://localhost:59017 to http://localhost:5901 (last number 7 deleted) worked for me. enter image description here

M Fuat
  • 1,330
  • 3
  • 12
  • 24
1

I had exactly the same problem with IIS Express that seemingly appeared out of nowhere. My solution was to simply open IIS Manager and restart IIS (in the right-side panel under Actions -> Manage Server). As a result, project start-up resumed working right away.

Mike O.
  • 61
  • 6
1

I was facing same issue, i tried all the way, i did not get proper solution. Finally i was resolved using below steps. In VS goto Tools=>Options=>Projects and solutions=>Web projects=> click checkbox -Use the 64 bit version of IIS express for website and projects.

With this i came out of my issue.

1

Another thing to try if nothing works (or if you just want to get it working quick):

Uninstall IIS Express, and then re-install it - can be done from Visual Studio Installer components (Add/Remove).

Yovav
  • 2,557
  • 2
  • 32
  • 53
1

All the above solutions did not work for me, however what worked was a simple fix after going through multiple solution;

Please follow the steps below;

  1. Go to your project/main solution folder in visual studio
  2. Right click on it and choose properties
  3. Go to the debug tab
  4. Scroll down to the Web Server Settings and turn off SSL

enter image description here

  1. Run your solution again, and you should be able to continue without errors
Umar Kayondo
  • 405
  • 4
  • 9
0

Another option, and the one I prefer because one should not have to waste time fighting with IISExpress, is to run your project launch profile and not the IISExpress one.

Blazor is a .NET Core app so you can debug it with Kestrel.

Crowcoder
  • 11,250
  • 3
  • 36
  • 45
  • 1
    This breaks the auto-reload feature that you get with IIS Express and doesn't answer the OP's question. – Christopher Haws Aug 21 '20 at 19:43
  • @ChristopherHaws I'm not sure which technique for hot reloading Blazor you are talking about but running as a console app absolutely does not break that. Additionally, it is perfectly acceptable for answers to be helpful, they don't have to be "the" answer. Thanks for your opinion but but IIS Express is junk and I'm not going to use it, and I get by just fine without it. – Crowcoder Aug 22 '20 at 11:27
  • @ChristopherHaws I just did some research and trialing. IIS Express is worse than other reload solutions for Blazor because you can't use it while debugging. – Crowcoder Aug 22 '20 at 11:42
  • 1
    Not sure what you are talking about, I use IIS Express everyday for debugging. Also, I didn't say hot reload, that is a feature in the works from the ASP.NET team. At this point in time, there are two options for "automatically reloading when changes are made". 1) Use IIS Express (which automatically reloads when there are changes made to code while not debugging) or 2) Use dotnet run watch (which in .NET 5 gives a similar experience to the IIS Express one). As for using dotnet run (which is what this answer is talking about), this does not allow the site to reload automatically – Christopher Haws Sep 17 '20 at 02:20
  • @ChristopherHaws its the best when people tell me what I already know. Thank you. My answer is helpful for people having this experience, it is an alternative. I knew all along it is not "the" answer but at least one person found it helpful enough to upvote so it adds value to the community. I can't count the times IISExpress has decided to lose its mind, why deal with it if you don't need to? – Crowcoder Sep 17 '20 at 16:55
  • 1
    The fix for something that is not working is not to use something else. The solution provided by @broguyman actually fixes the issue raised by the OP's question. – Christopher Haws Sep 17 '20 at 17:52
0

I seem to have this annoying issue when there are more than one solution with the same name on the same workstation. The host file ends up having names app, app(1), app(2), app(N) and so on. The solution here is to manually adjust the host file to your likings in \app(N).vs\app\config\applicationhost.config to align with whatever port you set in Properties>Web>Project URL. You may also need to unload project and set the same port number in project config.

Dmitri K
  • 634
  • 6
  • 13
0

Rebooting my computer was the simplest "solution"

herve
  • 525
  • 6
  • 17
0

Have you checked if you have any startup errors in your application itself?

In case of any technical misconfiguration during startup, it might be a viable solution to stop the application.

tme5092
  • 91
  • 1
  • 4
-1

I had the same issue. I was connected to my organization VPN. I simply disconnected the VPN, restarted IIS and tried again. It works fine now,