139

I attempted to run my web service through visual studio. I faced an issue like :

---------------------------
Microsoft Visual Studio
---------------------------
Unable to launch the IIS Express Web server.

Failed to register URL "http://localhost:63591/" for site "xxxxxx" application
"/". Error description: The process cannot access the file because it is being
used by another process. (0x80070020)

---------------------------
OK   
---------------------------

I saw the task manager and found that PID 4 is used by System and its Description is NT Kernel & System. So I tried to stop the http service. All dependency services stopped. But I am facing an issue in stopping http service like

The service is starting or stopping.  Please try again later.

So, I tried to stop and start the service manually. But the End process is disabled. It will be helpful if anyone could help with this issue

Lucas
  • 16,575
  • 5
  • 43
  • 40
Priya
  • 1,431
  • 2
  • 9
  • 6
  • 1
    seeing the issue after updating Windows 10: https://developercommunity.visualstudio.com/content/problem/580466/cannot-start-iis-express-0x80070020.html – XoXo Dec 03 '19 at 15:21
  • fwiw, the above link points to a link [here](https://programmingflow.com/2015/08/28/solved-iis-express-failed-to-register-url-access-is-denied.html), which says you can try `netsh http add iplisten ipaddress=::` – XoXo Nov 02 '20 at 13:55

29 Answers29

158

From https://www.davidsalter.co.uk/unable-to-launch-the-iis-express-web-server-error-0x80070020/

Error code 0x80070020 means ERROR_SHARING_VIOLATION, which in the case of IIS Express (or IIS) means that the port that it is attempting to listen on is being used by another process.

Use the netstat command to find out which application is using the port.

netstat -ao | findstr <port_number_to_search_for>

The a parameter tells netstat to display all connections and listening ports.

The o parameter tells netstat to display the process ID associated with the connection.

Running the above netstat command will produce output such as:

C:\>netstat -ao | findstr 4026
TCP    12.0.0.1:4026        cs-pc:4026         LISTENING       9544

The last number displayed (9544 here) is the process ID.

Chris Schiffhauer
  • 16,430
  • 15
  • 74
  • 84
  • 13
    Great answer! Not only do you describe the solution, you also include the meaning of the parameters. I wish all answers were like this! – Christian Payne Feb 13 '16 at 03:03
  • This solution doesn't help me. But I open project with VS2010 instead of VS2015 and in helps. – Eugene Maksimov May 12 '16 at 13:03
  • 8
    This helped me, and it turned out the offending PID was Chrome.exe. I restarted Chrome, and the problem went away. – astrosteve Jun 28 '16 at 16:47
  • 1
    ...and then what? Process ID 9544. What does that mean? – Christine Aug 18 '16 at 20:49
  • 1
    Great answer. Using this I found that skype was listening on both port 80 and port 443. I killed skype and was then able to launch iisexpress as normal, now showing my extra bindings for ports 80 and 443 – Alastair Sep 20 '16 at 06:07
  • @Hill I agree that it would be helpful for the answer to tell you what to do once you have the process ID. In Windows, each process has a process ID, which can be found by running the command "tasklist" in command prompt. Since you know the ID, you could then see which process is trying to use the same port. – hatmatbbat10 Oct 19 '16 at 01:15
  • 4
    run in an elevated cmd window `TASKKILL /PID 2756 /F` replace `2756` with your process ID – stackoverfloweth Jun 23 '17 at 00:41
  • Why does explorer.exe use any port, interesting. Thanks for the solution. – ddagsan Oct 25 '17 at 05:58
  • 23
    This can be made considerably faster with the `-n` switch as well -- it uses "numeric" output, which means it doesn't waste time querying DNS in order to resolve IP addresses into hostnames. – Tullo_x86 Feb 27 '18 at 22:08
  • I just did as @astrosteve and restarted chrome (using vs2017 on win10) – mortenma71 Mar 13 '18 at 05:39
  • I just wanted to mention for others that this didn't find anything using the port but changing the port localhost ran on did fix the issue. So if all else fails, just change it anyways. – Shelby115 Oct 09 '18 at 17:28
  • In my case the port 50393 was used by a remote desktop connection – Giox Mar 20 '19 at 10:06
  • 1
    I ran taskkill /PID 4 /F from a PowerShell window that was run as administrator and I got an error message 'Access denied' – Kevin Burton Nov 27 '19 at 14:09
  • 1
    I've run "netstat -ano | findstr " with the port that I'm trying to run on, and it isn't found. – Jeff Dege Sep 16 '20 at 18:07
  • Thanks! This helped a ton. After finding the process Id, I ended the task from task manager and everything is working. Don't need to restart or delete .vs folder like many other solutions. – E Benzle Oct 20 '20 at 13:45
131

I had a similar issue when trying to run a project from Visual Studio 2019 on Windows 10. The application could not start because the port was apparently being used by another process. However, the netstat command showed that the port was not being used by any application.

After spending 2-days Googling I found a solution that worked for me. The port I was trying to use was in the excluded port range which you can see by running the command:

netsh interface ipv4 show excludedportrange protocol=tcp

The culprits that reserved these ports in my case were Docker for Windows and Hyper-V

The Solution

I uninstalled Docker (as I did not need it) and disabled Hyper-V. To disable Hyper-V: Go to: Control Panel-> Programs and Features-> Turn Windows features on or off. Untick Hyper-V and restart the computer.

After the restart the command netsh interface ipv4 show excludedportrange protocol=tcp showed no ports reserved.

I then added the port for my application to the excluded port range by running the following command from an elevated command line:

netsh int ipv4 add excludedportrange protocol=tcp startport=50403 numberofports=1 store=persistent

Then I reenabled Hyper-V (Docker can be reinstalled if needed) and restarted the computer again.

Hyper-V now reserved its ports without interfering with the port used by my application: Reserved Port Ranges

Philip Trenwith
  • 2,121
  • 1
  • 9
  • 9
  • This worked for me, except I need Docker so I just disabled it on start up instead of uninstalling it. – cderrick Apr 03 '20 at 19:58
  • 10
    I ended up changing my port out of the excluded range.. but THIS saved me tons of time. Thank you. – Cory Apr 12 '20 at 23:07
  • 3
    Like @Cory I changed my port in vs to be something outside the ranges, annoy because now i have to change referencing apps every time i do this but better than a full restart. – Nick Rubino Apr 29 '20 at 02:30
  • 1
    I was looking for this for *years*. I'm wondering if there's a way to determine exactly what app **stole** my ports? Thanks. – Simon Mourier Aug 12 '20 at 21:03
  • 1
    Disabling Hyper-V and rebooting fixed it for me – Kyle Burkett Aug 17 '20 at 18:03
  • I reserved my ports in netsh but now I get the IIS Epress error because of my reservations. Did I miss something? – Erik Simon Aug 27 '20 at 08:48
  • I changed the port and then just had to run the command below to get it to work, thanks! netsh http add urlacl url=http://localhost:49914/ user=Everyone – pwhe23 Sep 01 '20 at 17:16
  • This IS the right answer and should be marked as so. – onefootswill Sep 02 '20 at 22:59
  • Docker was causing this issue for mw - thanks for this! – James Culshaw Sep 28 '20 at 12:39
  • Hyper-V was causing the issue for me. Perfect answer! Thank you so much! I think the two answers should be merged into a fully comprehensive one. – A.Buonanni Oct 27 '20 at 16:16
  • 1
    Also changing the port number used by the project may be "not so friendly". Check [here](https://developercommunity.visualstudio.com/content/problem/353750/cannot-change-port-number.html) on a solution for changing both http and https port numbers (the last "trick" works only for https port number). – A.Buonanni Oct 27 '20 at 16:41
  • I've got the same problem as Erik Simon. I had the port in the excluded range, disabled HyperV, put the single port in the exclusions, enabled HyperV again - and it doesn't work, with the same error, which seems quite logical to me, because the port still is in the excluded range, which seemed to make the problem in the first place! Although MS is stating "When you [exclude a range of ports], only a program or process that specifically requests a port that is in the excluded range can use that port. " - so it should have worked in the first place?!? – Eike Dec 22 '20 at 14:29
  • Thanks. This too was my problem. I had to make sure both http and https ports run out of the excluded ranges (and of course in different ports each ☺). – Silvestre Jan 28 '21 at 00:41
  • I had Docker installed in Ubuntu running on WSL2. Disabling Hyper-V did not resolve the issue. Instead I just changed the port on the URL in launchSettings.json - on "applicationUrl". – Stuart Welch Feb 07 '21 at 09:21
32

I had the same problem. I just restarted Visual Studio and it worked.

MusicAndCode
  • 713
  • 7
  • 18
  • 2
    My computer had restarted from updates and netstat showed no process using the port. This was only solution that worked. Thanks! – dwp4ge Apr 15 '16 at 13:03
  • 2
    had to restart my machine also – Mahmoud Hboubati Aug 21 '17 at 07:00
  • 1
    Surprisingly restarting Visual Studio (2017) worked as well for me. Thanks! – Thomas Gassmann Mar 05 '18 at 14:26
  • In my case, my Windows 10 box blue-screened, and I had to reboot **twice**. Other web site projects worked fine (different local port), and none of the other answers here worked. Changing the port for the project didn't fix it either. There must be some other config in IIS Express itself. – Granger Feb 08 '19 at 19:21
  • It seems like this happens to me whenever I run a project in VS 2019 with debugging using F5, then later try to run it without debugging using Ctrl+F5 which is when it fails. A restart fixes it, though I wish I could actually prevent it from happening in the first place. – pwhe23 Jan 07 '20 at 18:37
29

I had the same Issue. As @Kautsky Lozano mentions above Another application is using that port.

So [for a Windows OS] just:

  • Open Resource Monitor (Task Manager -> Performance -> Open Resource Monitor )
  • Click on the Network tab.
  • And at TCP Connections find the application that uses the Local Port that IIS Express uses and close it. (it was firefox on my case)
Zoti
  • 706
  • 10
  • 22
13

If netstat doesn't show anything already using the port

netstat -ano | findstr <your port number>

The port might be excluded, try this command to see if the range is blocked by something else:

netsh interface ipv4 show excludedportrange protocol=tcp

You can try to unblock the range from the start port for a number of ports (need Command Prompt with Administrator):

netsh int ip delete excludedportrange protocol=tcp numberofports=<number of ports> startport=<start port>

For me I couldn't unblock these, I just got "Access is denied", so I ended up having to pick another port for my site.

John Leonard
  • 487
  • 6
  • 16
  • Nothing else but this helped. I could see the range included my port number `netsh interface ipv4 show excludedportrange protocol=tcp`. Lot of time was wasted until I found this to get it resolved. Thanks lot @john Leonard – jAntoni Oct 28 '20 at 08:00
12

I ran into the same problem after we had upgraded a solution from Visual Studio 2012 to 2015. I had come here and ran netstat only to find that no other application was using the same ports. It turns out I had the same sites with the same ports mapped in the applicationhost.config at Users/<username>/Documents/IISExpress/config and the applicationhost.config in the .vs folder inside my solution. I should note that the problem didn't start right after the upgrade either. It just start failing consistently one morning. A couple reboots didn't seem to solve the problem either.

Removing the conflicted sites from the one stored in my Documents and restarting Visual Studio solved the problem.

9

Solution that worked from me is,

To fix this you must temporarily disable the winnat service, this is simply done by running this command (must be run as administrator)

net stop winnat

Start your docker services and start winnat again

net start winnat

Solution posted at http://www.herlitz.nu/2020/12/01/docker-error-ports-are-not-available-on-windows-10/

Yogesh Thorat
  • 91
  • 1
  • 3
6

After updating Windows 10 and/or Visual Studio 16+ it might happen due to an internal bug that IISExpress fails to register any development website because it no longer accepts localhost connections.

To fix the issue, you just have to register again the binding. To do so, run from an administrative shell the following command:

netsh http add iplisten ipaddress=:: 
Yennefer
  • 4,420
  • 6
  • 25
  • 35
4

Another application is using that port. This could help you

Kautsky Lozano
  • 562
  • 9
  • 21
4

I just had this issue even though netstat did not show any conflicts.

The following fixed it for me:

  1. Close Visual Studio
  2. Open up File Explorer
  3. Navigate to the folder of the offending project
  4. Delete the obj and bin folders
  5. Delete the *.user file (this is probably optional)
  6. Restart Visual Studio and try again
AaronK
  • 308
  • 3
  • 14
3

I had this problem when upgrading an MVC project. I copied over the newer-MVC .csproj over my existing .csproj file then worked back to a fully working Project. What I failed to consider is the existing port number in the old .csproj. The new project had a new port number, yet shared the Project/Assembly Name. That was enough to make IIS Express lose its mind and throw this exception.

Just digging the old port number out of git and changing the IIS Express URL to include it in Project Settings was enough to fix it.

Community
  • 1
  • 1
Chris Moschini
  • 33,398
  • 18
  • 147
  • 176
3

In my case, doing the following did the trick:

  • Delete the Site from .vs\\config\applicationhost.config
  • Delete the Site from Documents\IISExpress\config\applicationhost.config
  • Delete the IISUrl from the .csproj

When I restarted Visual Studio, it assigned the project a completely new port number and ran perfectly

djeastm
  • 81
  • 5
2

The easiest first pass at this without getting into the command console is to just shut down all applications (including VS), then launch VS by itself and try it again. There is likely another application like your browser causing the conflict. In my case Chrome caused it and was solved when shutting everything down and restarting VS. I opened Chrome again and everything was fine.

The netstat stuff above is useful, but to me that's only if you can't do what I'm suggesting.

2

Go to Web Project Properties >> Web >> Project Url >> Change port i.e: http://localhost:22345/ => http://localhost:22346/ Hope this help!

binhtruong.it
  • 151
  • 1
  • 3
  • This happened to me today and I just had to keep trying port numbers until it started working again. ¯\_(ツ)_/¯ – Steve Owen Feb 11 '21 at 12:21
2

to summarize all the answers. There are 2 solutions. Both worked for me. - Solution #1 Kill the app that uses the same port. - Solution #2 Configure IIS Express to use a different port for your project.

Solution #1 (supposing the port in the error message was 443) Run in the command line:

netstat -ao | findstr 443

it returns: TCP 0.0.0.0:443 pe01:0 LISTENING 2904 The last number (thanks to @chris-schiffhauer) is PID to kill. Go to the Task Manager -> Processes -> [Show Processes From All users], Kill a process with PID=2904. In my case, it was VmWare host.

Solution #2 (Supposing message was: Failed to register URL "http://localhost:433/" for site "MyProject.Website0"...). Open the folloing file in notedpad++: C:\Users\MY_USER_NAME\Documents\IISExpress\config\applicationhost.config Find in it a line containing:

<site name="MyProject.Website0" id="...
...
            <bindings>
                <binding protocol="http" bindingInformation="*:80:localhost" />
                <binding protocol="https" bindingInformation="*:443:localhost" />
            </bindings>

Either change 433 to something else, like 4330 or delete the conflicting <binding.../> tag.

epox
  • 4,537
  • 36
  • 26
2

Port numbers do not match

In my case the problem was in my Bindings Tags found in the config file in .vs under my solution folder, the port numbers did not match. The bindings were as follows

<bindings>
     <binding protocol="http" bindingInformation=":16433:localhost" />
</bindings>

And in my settings i had url set as http://localhost:1943/

So what i did was to delete inside binding and run my web app, then it generated new binding with a different number then i copied the new generated port to my settings, then the error went away.

  • This time around (I've had this problem before, its been one of the many causes presented in various answers here) this was the cause. – speciesUnknown Nov 07 '19 at 09:57
2

I ran into this problem in Visual Studio 2019 today and spent 3 hours before finally figuring out the problem. Visual Studio uses 2 files to track the SSL port number, so you have to fix both and you have to fix both while Visual Studio is closed. The two files are the applicationhost.config file that is in the .vs\???\config folder of your solution; and also the .csproj.user folder of your web project. Edit both files and removing the offending configs. Maybe even just delete both files. Then re-open your app in Visual Studio. Good luck!

Rob Kraft
  • 893
  • 8
  • 17
  • 1
    If your solution contains a plain old fashioned website (not a web application) then the port numbers are also in the solution file .sln – nuander Dec 04 '19 at 15:59
  • For old fashioned website editing both .(sln solution file and applicationhost.config file) worked. – Himalaya Garg Feb 08 '21 at 04:03
2
  1. Close visual studio
  2. delete ".vs" folder
  3. Try change port "localhost:8080"

It worked for me.

1

I was able fix this problem by removing everything from <site> to </site> tags in

Users/<username>/Documents/IISExpress/config/applicatiohost.config file

<sites>
  <site>
     .
     .   ===> remove this content including the <site> and </site> tags.
     .
  </site>
</sites>
nPcomp
  • 5,621
  • 1
  • 37
  • 45
1

Having just wasted half a day trying to fix this same issue, I felt I should add the solution which eventually worked for me.

TL;DR If netstatindicates that the problematic isn't in use, still try a few others in a totally different range

I've run into this problem before but usually find restarting visual studio, changing ports (increment by 1) or rebooting do the trick. However on this occasion none of this helped, and netstat wasn't finding a conflicting process. I even reinstalled IIS and visual studio and removed several other programs which I suspected could be interfering. It seemed as though IIS was trying to launch multiple instances of the same site.

Eventually I tried running netstat without findstr. I visually scanned the list of active ports and noticed that although the ones I had tried were not listed, there were a few processes using ports in a similar range. So instead I looked for a range which was free, picked a port number and that seems to now be working.

I'd love to hear if anybody can explain why this might have worked?

Phil
  • 741
  • 9
  • 16
1

I followed @Zoti's instructions and used Resource Monitor to find the port in question.

Turns out Outlook had randomly been assigned the port for it's communications channel. Moral of the story being, it could be absolutely anything.

Greg B
  • 13,819
  • 18
  • 78
  • 132
1

Reason for this error that is you give the wrong port number to your application.

just use http ports for your application to run

use the port near to 8080 number, i.e:

localhost:8090

to change the port for you application in visual-Studio

goto project properties > web > Server > ProjectUrl

Talha Rafique
  • 1,519
  • 1
  • 8
  • 7
1

IIS Express Failing to Start Solution in Visual Studio

  • Go to Task Manager
  • Search for "Application Frame Host" Process
  • End this Process
  • Try to Run Again
Qamar Zaman
  • 1,525
  • 1
  • 7
  • 10
1

Tried everything, was at my wits end.

Then tried closing EVERYTHING that was open with an internet connection on my machine.

Chrome, Steam, Slack, etc... all swiftly given the boot.

Problem solved.

Stuart Aitken
  • 691
  • 10
  • 23
0

I tried the following already:

  • Restarted Visual Studio
  • Check all available ports that might be listening to my specific number but it always return zero results. No processes is listening in my port.
  • I also tried using this but zero results.

    netstat -aon | find ":80"

  • I also tried using but also return zero results.

    netstat -ao | findstr

So what I did is delete this "Microsoft.VsHub.Server.HttpHostx64.exe" then my project successfully started and launch in browser. The error was fixed. I am not sure why but it works.

Here is the screenshot:

enter image description here

Willy David Jr
  • 6,916
  • 3
  • 34
  • 45
0

I had the same problem but it resolved when I restarted using admin privileges. (Might have just been the restart)

Vaibhav Garg
  • 3,409
  • 3
  • 28
  • 53
0

I had the same problem today, and nothing I found on the internet worked. I have been using port 2057 for years, but suddenly it didn't work any more. Changing it to another low number like 2058 gave same error message, but when I changed it to 20057, everything worked again. Maybe something changed with the way the lower port numbers are handled.

Bogi lenvig
  • 88
  • 1
  • 7
0

I my case, I binded the application to run on LAN, i.e connect to the application from another devices like mobile. It has to run visual studio as administrator.

Shaahin
  • 962
  • 2
  • 12
  • 20
0

I'm using VS2019 Version 16.10.0 Preview 2.0 and I just went to here:

untick and save anв tick

Unchecked Enable SSL => Save => check it back => Save.

alvipeo
  • 3,148
  • 3
  • 28
  • 85