21

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?

Do Nhu Vy
  • 33,131
  • 37
  • 143
  • 202
  • 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

13 Answers13

22

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
  • 7,463
  • 5
  • 37
  • 42
  • 1
    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
  • 1
    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
  • `$ 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
19

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
  • 24,276
  • 25
  • 91
  • 195
12

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
  • 332
  • 2
  • 10
broguyman
  • 1,236
  • 3
  • 19
  • 36
3

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
  • 2,955
  • 18
  • 25
  • 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
3

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]
  • 1
    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
3

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

Alex
  • 208
  • 3
  • 8
2

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
  • 6,104
  • 3
  • 28
  • 39
1

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
  • 9,566
  • 3
  • 30
  • 39
  • 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
  • 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
  • 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
1

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

stuartdotnet
  • 2,600
  • 3
  • 31
  • 35
  • 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,022
  • 2
  • 11
  • 22
0

Removing .vs folder will solve this issue.

  1. Go to application location
  2. Remove .vs folder(hidden folder)
  3. Start project again!
0

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,

0

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.