52

I am using Microsoft Visual Studio 2019 Community preview, version 16.4.0 Preview 1.0. I just updated to Windows 10 Pro Version 1903 OS build 18362.418. With an ASP.NET Core 3 web app project (Blazor Server), When I press F5, I catch an 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.

Whether I choose or do not choose the option "Enable native code debugging", no success.

How do I fix it?

2

22 Answers 22

61

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/ 
Sign up to request clarification or add additional context in comments.

3 Comments

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.
$ 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.
Updating my Applicationhost Config fixed the error for me
43

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

9 Comments

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.
tried a lot of these other solutions... only thing that worked was to close SLN, Delete the .vs folder, reopen solution.
Closing the solution, ditching the .vs folder and recycling IIS Express did the trick for me.
This has worked for me a couple different times now
@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 <binding> tag I had problems with.
|
24

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

Comments

15

Removing .vs folder will solve this issue.

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

Comments

10

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.

5 Comments

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 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 :)
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.
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.
@Tony_Henrich - Maybe the system should check to make sure the port is not already in use... js
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.

2 Comments

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.
Yeah, I think I could shorten it to "friends don't let friends use IIS Express"
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]

2 Comments

To shed some light why this may work is because this forces the regeneration of ".vs\PROJECTNAME\config\applicationhost.config".
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
5

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

Comments

2

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

1 Comment

In 2024 This is still the way
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).

Comments

1

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

1 Comment

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

Comments

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.

Comments

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.

Comments

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

Comments

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.

6 Comments

This breaks the auto-reload feature that you get with IIS Express and doesn't answer the OP's question.
@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.
@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.
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
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.
|
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.

Comments

0

Rebooting my computer was the simplest "solution"

Comments

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.

Comments

0

In my case just needed to install missing .Net SDK version.

Try running app dotnet run in terminal, you'll get more info.

Comments

0

I had the same issue, deleting the VS folder did not work for me.

Unloading and loading the project resolved the issue for me.

You can do this in Visual studio by right clicking the project and selecting unload project and then clicking load project.

Comments

-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,

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.