138

We know a random port number is assigned to a web application in Visual Studio. It works fine in my office desktop. But when I pull the code onto my laptop (from VisualStudio.com) and run the web app. I got a message, saying,

The specified port is in use

Port 10360 is already being used by another application.

Recommendations

  1. Try switching to port other than 10360 and higher than 1024.
  2. Stop the application that is using port 10360.

I can fix it using Recommendation #1 by changing the port into something else like 13333. But I am very curious what happened to port 10360. How can I check what application is using port 10360? How can I stop that application?

Blaise
  • 21,314
  • 28
  • 108
  • 169
  • i had the same problem. My issue was that i had several web projects in the same solution. Even though they were not running . One of the other projects used the same port. Just make sure any given project uses its own port. – Menace Dec 17 '17 at 18:31

33 Answers33

116

I had a similar issue running Visual Studio 2019 on Windows 10. Some solutions that worked for others seemed to include:

  1. Changing the application port number.
  2. Have Visual studio automatically assign a port number each time the application start.
  3. Restart Visual Studio
  4. Restart the computer.

Unfortunately, none of these solutions worked for me, assigning another port number did work but was not an acceptable solution as it was important for my application to run on a specified port.

The Solution

First I ran the command:

netsh http add iplisten ipaddress=::

from an elevated command-line process. This solved the initial error, when attempting to run the application I no longer got the "port in use" error, instead, I now got an error stating the application was unable to bind to the port because administrative privileges were required. (although I was running Visual Studio as administrator)

The second error was caused by Hyper-V that adds ports to the Port Exclusion Range, the port my application uses was in one of these exclusion ranges. You can view these ports by running the following command: netsh interface ipv4 show excludedportrange protocol=tcp

To solve this second error:

  1. Disable Hyper-V: Control Panel-> Programs and Features-> Turn Windows features on or off. Untick Hyper-V
  2. Restart the computer.
  3. Add the port you are using to the port exclusion range: netsh int ipv4 add excludedportrange protocol=tcp startport=50403 numberofports=1 store=persistent
  4. Reenable Hyper-V
  5. Restart the computer

From here everything worked perfectly.

Philip Trenwith
  • 3,881
  • 2
  • 11
  • 10
  • Wow, the only thing that got me to the solution. Disabling Hyper-V got me a Windows 10 frowny BSOD thanks to the corporate build, but thanks to `netsh interface ipv4 show excludedportrange protocol=tcp` I was at least able to pick a new port for the project. – SharpC Jan 24 '20 at 09:24
  • 10
    DUDE Not only was this the correct answer, you actually explained it instead of just dumping a CMD script (which is fine btw for most cases). Thank you so much, would upvote 100x if I could. – Ryanman Apr 10 '20 at 21:07
  • 12
    Thank you, this happened to me after installing docker. – MaxPower Apr 12 '20 at 22:54
  • 1
    This saved me, I spent all my days and was very frustrated. This leads me to the correct solution. https://github.com/docker/for-win/issues/3171#issuecomment-459205576 – muhammad kashif May 27 '20 at 09:10
  • 1
    Had this issue due to Hyper-V. Thanks for this! – DylanSp Jun 16 '20 at 20:36
  • @PhilipTrenwith Detailed one :). Optionally, for a quick solution, unblocked ports can be used as in my answer. – Naveen Kumar V Jul 25 '20 at 10:16
  • 1
    @PhilipTrenwith Sir, you are a lifesaver. Spend hours figuring this out and your solution fixed it. I also had the issue after setting up docker. – Nicolas Sep 02 '20 at 09:24
  • Note: You don't need to disable and re-enable Hyper-V if you're happy just picking a port that isn't in those ranges. In my case the SSL port was fine but the non-SSL port was excluded, changing it make everything work without registering :: or disabling Hyper-V. – IronSean Dec 08 '20 at 20:53
  • I can't upvote this answer enough. I could run it on a different port but randomly selecting a different port kept getting the same error. This gave me the list of unallowed ports so I could intelligently choose one that would work. – ahwm Apr 21 '21 at 20:52
  • this is the way – marvhen Jul 30 '21 at 14:14
  • This did not work for me. I ended up disabling Hyper-V and leaving it off. Which got me past the port issue, but it hasn't resolved all of the issues running the sites.. – bambams Jun 01 '22 at 16:13
  • After trying many solutions. Finally this worked for me. It was the issue related to docker which I installed. I had to disable virtualization from Bios as there is no option in control panel to disable(Windows 11). thanks – prisan Jun 07 '22 at 13:07
  • 1
    The issue can happen by starting two visual studio sessions at the same exact time. They both try to access the same port. Before trying the above, just restart your machine. Then start the visual studio sessions a minute or more apart. – Robert Smith Feb 06 '23 at 16:01
  • @RobertSmith I think that is what happened with me, that I started two instances of Visual Studio in quick succession. I still had to follow all of the steps in this answer to fix the issue, but in trying to figure out what changed to cause this issue, starting two instances of Visual Studio is the only thing I can confirm that did happen. To the best of my knowledge there wasn't a windows update and there was nothing new (like Docker) that was installed that could have introduced the issue. – Gharbad The Weak May 15 '23 at 16:49
61

i solve the problem this way...

File -> Open -> Web Site... enter image description here

After that select Local IIS under IIS Express Site remove the unwanted project.

hope this help.

Community
  • 1
  • 1
yean
  • 1,307
  • 12
  • 8
43

SIMPLE SOLUTION THAT WORKED FOR ME: (Credits to combination of other's answers)

**My System Info:**
Windows 10 build : 1809
IIS Version      : 10.0.17763.1
Hyper-V          : Enabled
Docker           : Installed - 2.3.0.2 (45183)
  • Check for blocked ports range in CMD (admin)

    >> netsh interface ipv4 show excludedportrange protocol=tcp
    
    (Sample output):
    Protocol tcp Port Exclusion Ranges
    Start Port    End Port
    ----------    --------
    49696       49795         (SEE HERE, 49796 to 49895 is not blocked)
    49896       49995
    ... list goes on ...
    
  • Open Visual Studio and Navigate to > Project > Properties > Web > Servers > Project Url

  • Use the Port that is not blocked.

    (Sample port):
    http://localhost:49796/
    
  • Restart Visual Studio (if required)

  • Have a coffee and share love. (required) :)

Naveen Kumar V
  • 2,559
  • 2
  • 29
  • 43
42
  1. change it in solution (right Click) -> property -> web tab
  2. Click Create Virtual Directory (in front of project Url textbox)

IIS Express port change for fixing port in use

Iman
  • 17,932
  • 6
  • 80
  • 90
  • 4
    I don't want to change my .sln property page over and over again. In my case, the port defined on the property page (as you've shown above) becomes locked when I do something in Visual Studio that causes Visual Studio to crash. – bkwdesign Dec 18 '15 at 14:18
  • @bkwdesign , i have no idea about the crash , maybe you should run with Admin Privilege and also create virtual directory or update your VS to latest version or at last just switch to standard IIS Role – Iman Dec 20 '15 at 08:17
38

This was haunting me for over a year!

For me,

  • no website was running iin IIS Express
  • nothing was using the port as determined by running: netstat -ano at the command line.

The solution was to run

netsh http add iplisten ipaddress=::

from the command line.

Happy days, and credit to: James Bryant! https://developercommunity.visualstudio.com/content/problem/110767/specified-port-is-in-use.html

Liam Fleming
  • 1,016
  • 12
  • 17
  • no idea what happened, no idea what that command does, but it worked where other solutions here failed – sksallaj Nov 13 '18 at 22:54
  • 8
    This command broke my IIS, be careful running this. Had to run netsh http delete iplisten ipaddress=:: for my local IIS sites to work again. – Steve Jan 28 '19 at 17:07
  • Broke my IIS as well, it started saying it needs Administrative privileges to run. Had to revert it. – jswetzen Nov 20 '20 at 08:18
  • 2
    For those getting Administrator priviledge issues after this, look at @Philip Trenwith's answer, it could be Hyper-V excluded port ranges. – IronSean Dec 08 '20 at 20:52
30

I had the same problem, but no proccess appeared neither in netstat nor in resmon.

What solved the problem for me was closing all the open browser windows.

Clangon
  • 1,408
  • 2
  • 18
  • 24
  • 1
    Wow. That worked for me too. Can anyone explain why? – SJC Oct 25 '16 at 06:10
  • Confirming that this sometimes fixes the problem (using Firefox as standard browser), and it makes absolutely no sense. – Florian Winter Jul 12 '17 at 07:57
  • 4
    This didnt work for me. No running apps. Just a port in use. No running web pages. Just an error. What a pain. – Mike Oct 12 '17 at 15:32
  • 3
    I think the reason this works is when you make a web request the browser is using an arbitrary number for the *source* port (usually between 49152 - 65535) and this is conflicting with the port configured in IIS – Hugh Jeffner May 15 '18 at 19:35
  • This worked for me too. It didnt make sense as the app blocking the port had no reason to be using it. – James Westgate Apr 23 '19 at 13:54
23

The cause of this issue in my own case is a bit different. Everything was working fine until I started docker to do some other stuff. Starting docker, in one way or the other, added some new ranges of ports to the Port Exclusion Ranges. What to do:

  1. Open command prompt (As an administrator)
  2. run: netsh interface ipv4 show excludedportrange protocol=tcp (You should see the port your application is using in the excluded port ranges)
  3. run: net stop winnat
  4. run: netsh interface ipv4 show excludedportrange protocol=tcp (by this time, the Administered port exclusions ranges should reduce)
  5. run net start winnat.

If the problem was caused by Windows NAT Driver (winnat), then you should be good by now.

abibtj
  • 331
  • 2
  • 3
  • This worked for me – Martin Smith Dec 21 '21 at 06:10
  • It worked for me, in my scenario the problem occured after 'cleaning-up' the docker images, it seems the port was locked for one of the images and the docker clean-up removed the image but didn't deallocate the port. after that process, the port was not even showing in netstat, even restarting the machine didn't help. but net stop/start helped.. very weird. – G.Y Jun 15 '22 at 09:12
  • helped on Win11 Pro for IIS Express related issues – r.sumesh Mar 09 '23 at 11:19
20

You're looking for netstat.

Open an administrative command shell and run

netstat -aob

And look for port 10360. It'll show you what executable opened the port and what PID to look up in Task Manager. (Actually, run netstat -? in an unprivileged shell first, because I don't approve of blindly running anything you don't understand, especially in a privileged context.)

Here's what the switches do:

-a shows all connections or open ports, not just active ones - the port you want is probably listening, not active.

-o shows the owning PID of the connection or port, so you can find the process in Task Manager's Processes tab. (You might need to add the PID column in Task Manager. View->Select Columns)

-b shows the binary involved in opening the connection or port. This is the one that requires elevated access.

  • That's neat. Now I at least have the `PID` of the application. Thanks. – Blaise Mar 22 '14 at 03:28
  • 9
    That command will generate a lot of noise, so if you want to cut straight to the offending application, pipe the results to findstr like so: `netstat -aob | findstr '10360'` – kmkemp Apr 03 '15 at 14:15
  • 1
    All the other answers sent me off in the woods, this one actually allowed me to find the source and fix the problem. – Hugh Jeffner May 15 '18 at 19:27
  • Also, you can use nestat -aob -p TCP to only view TCP ports – Shiroy Apr 06 '19 at 16:35
13
  1. Close the VS
    1. Start again - right click and run as admin
    2. Run your project again.
Mansi
  • 131
  • 1
  • 2
  • if suppose that port is used by some another process changes port in project >properties > debug then run as admin works – Noman Chali May 04 '17 at 09:52
  • It's pretty sad but this worked. Nothing else worked. The error is compeletely wrong as I had no running processes under the port in question. This appears to be a bug from visual studio and IISExpress. It makes no sense why I had to close it out and run it again. – Mike Oct 12 '17 at 15:38
  • This step did not fix mine issue. – user1451111 Oct 19 '17 at 12:49
  • Happy and disturbed that one admin run is what it took after reboots, port changes, process kills, netstat hunts, iplisten changes. Continued to work when run as user. – Richard Feb 19 '19 at 17:11
  • For me as well, of all the solutions here, this is the one that worked for me. Why, oh why? – Peter Hahndorf Jan 03 '23 at 14:19
8

Running visual studio in administrative mode solved my issue

Mujtaba Zaidi
  • 629
  • 1
  • 6
  • 14
6
  1. Delete the .sln file, if you have one.
  2. Open the file C:\Users\NN\Documents\IISExpress\config\applicationhost.config
  3. Locate the problematic site in configuration/system.applicationHost/sites and delete the whole site section.
  4. "Open Web Site.." from Visual Studio and the project will be given a random new port.
Jonas Äppelgran
  • 2,617
  • 26
  • 30
6

For me the "The specified port is in use" error is usually fixed (well actually worked arround) by stopping the "Internet Connection Sharing (ICS)" (SharedAccess) and the "World Wide Web Publishing Service" (W3SVC) service.

After the project / ISS Express is started the stopped services can be started again without issues.

Whenever i receive the error the port (in the 50000 range) is definitely not in use (checked with netstat & tcpview).

It would be nice if Microsoft did some integration testing of Visual Studio / IIS Express along side with HyperV and the "normal" IIS Service OR gave some guidance on which port ranges to use for VS / IIS Express (and which ports to avoid).

Michel
  • 71
  • 1
  • 2
  • 1
    This was my issue and it took forever to track down because ICS apparently doesn't show up in netstat or Resource Monitor. Thanks! Stupid $%@*&&!)$*! – James Jun 02 '20 at 23:50
  • Thanks so much for posting this. This is the only thing that worked for me. I think it happened in between things working for web app development and then electing to share my Android phone internet connection via USB to my computer. And I did try everything, from the idea above (breaks things and needs to be deleted), to attempting to delete the reserved range (get access denied even as an administrator). Restarts, closing web browsers, etc, did not work until I tried this, so thanks again. – Alister Smith Dec 18 '20 at 03:33
  • Stopping ICS in Services fixed the issue for me. – Victorio Berra Mar 30 '22 at 22:20
5

netstat didn't show anything already using the port

netstat -ano | findstr <your port number> showed nothing for me. I found out that port was excluded using this command to see what ranges are reserved 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>

However, in my case I couldn't unblock the range, I just got "Access is denied", so I ended up having to pick another port for my site.

My original solution: The only thing that worked was deleting the .vs folder in the solution folder. (I've since found you can just delete the .vs/config/applicationhost.config instead to avoid losing so many settings).

John Leonard
  • 909
  • 11
  • 18
  • I thought this solution would work well but I still get the error. The port in question for me (3333) isn't appearing in netstat -a at all. – Chris Walsh Sep 16 '19 at 15:12
  • 1
    @ChrisWalsh this problem reoccurred for me & I've found out additional info why so I've updated my answer. You might be in the same boat as me, the port was not in use but reserved (excluded) by something else. – John Leonard Jan 24 '20 at 13:54
  • Nothing is using these ports. Try this solution https://stackoverflow.com/a/66290952/7084222 – Mabakay Mar 30 '21 at 08:24
  • this did it for me, somehow Windows all of a sudden had added my port number in the range of excludedportranges. using the netsh interface ipv4 show excludedportrange protocol=tcp showed me what range was available. – invalidusername Aug 23 '23 at 13:53
4

Visual studio 2015

  • Close all the files you have open inside Visual studio.
  • Then close application and exit Visual Studio.
  • Open Visual Studio and it should successfully run.

I hope this helps.

Daniel Ecker
  • 105
  • 13
saurav singh
  • 438
  • 6
  • 16
3

If netstat doesn't show anything, try a reboot.

For me, nothing appeared in netstat for my port. I tried closing Google Chrome browser windows as @Clangon and @J.T. Taylor suggested, but to no avail.

In the end a system reboot worked, however, so I can only assume that something else was secretly holding the port open. Or perhaps it just took longer than I was prepared to wait for the ports to be released after Chrome shut down.

Paul Stephenson
  • 67,682
  • 9
  • 49
  • 51
3

For me, close all application and restart the computer.

When window start, Open Visual studio first, then open browser and click run(F5).

Now it works. I don't know why.

OammieR
  • 2,800
  • 5
  • 30
  • 51
3

Open Task Manager and Just Close all processes of 'IIS Express System Tray' and 'IIS Express Worker Process' and Re-run the Project

Task Manager Process Details

Community
  • 1
  • 1
SumairIrshad
  • 1,641
  • 1
  • 13
  • 11
1

For me, the Google Chrome browser was the process which was using the port. Even after I closed Chrome, I found that the process still persisted (I allow Chrome to "run in background" so that I can receive desktop notifications). I went into Task Manager, and killed the Chrome browser process, and then started my web application, it worked like a charm.

J.T. Taylor
  • 4,147
  • 1
  • 23
  • 23
1

Open your csproj with for example Notepad ++ and scroll down to DevelopmentServerPort. Change it to something else as long as it's above 1024 like rekommended (so for example 22312). Also change the IISUrl to http://localhost:22312/. Save your changes and restart the project.

K.Oleksiak
  • 325
  • 1
  • 2
  • 15
1

In my case there was no application using specified port and elevated running of Visual Studio didn't help either.

What worked for me is to reinstall IIS Express and than restart computer.

Mirhat
  • 341
  • 3
  • 7
  • 20
1

For me it was an orphaned VBCSCompiler task from a previous run, that didn't shut down and was somehow interfering. Killing that task solved it.

https://developercommunity.visualstudio.com/content/problem/31482/vbcscompiler-does-not-shut-down.html

Thread Pitt
  • 716
  • 1
  • 6
  • 20
1

You need to configre this parameter by running the following in the administrative command prompt:

netsh http add iplisten ipaddress=::

0

click on the notification present on bottom of the task bar if you receiving the error like port in use then select the iiss icon right click then click on exit ,it work like charm for me

ashish Vicky
  • 11
  • 1
  • 4
0

I had same error showing up. I had my web service set as an application in IIS and I fixed it by:

Right-click on my WebService project inside my solution > Properties > Web > Under 'Servers' change from IIS Express to Local IIS (it will automatically create a Virtual Directory which is what you want)

Cristian G
  • 460
  • 1
  • 4
  • 22
0

When Port xxxx is already being used, there's always a PID (Process Id) elaborated with the error. Simply go to the task manager on the machine you are running the application, click on details, and you will identify what the other application is. You can then decide whether you want to end that process or not

Ken.Fukizi
  • 197
  • 1
  • 9
0

Just to add to this, I had the full IIS feature turned on for one of my machines and it seemed to cause this to happen intermittently.

I also got random complaints about needing Admin rights to bind sites after a while, I assume that somehow it was looking at the full IIS config (Which does require admin as it's not a per-user file).

If you are stuck and nothing else is helping (and you don't want to just choose another port) then check you have removed this if it is present.

Dan Harris
  • 1,336
  • 1
  • 21
  • 44
0

FWIW, I tried tons of these options and I didn't get anywhere. Then I realized I had installed VMWare Player just before the issue started. I uninstalled it, and this error went away.

I'm sure there's some way to make them coexist, but I don't really need Player so I just removed it. If you've tried all kinds of stuff and it's not working consider looking through any programs you've installed recently (especially those that deal with network adapters?) and see if that gets you anywhere.

trademark
  • 565
  • 4
  • 21
0

In Visual Studio 2017, select Project/Properties and then select the Web option. In the IIS section next to the default project URL click Create Virtual Directory. This solved the problem for me. I think in my case the default project Virtual Directory had been corrupted in some way following a debugging session.

user3615720
  • 91
  • 1
  • 2
0

To solve this issue follow the steps below:

  1. Open a CMD prompt in Administrator mode

  2. Then execute the command: netsh http add iplisten ipaddress=::

  3. After that, run the project

RoastBeast
  • 1,059
  • 2
  • 22
  • 38
Sumant Singh
  • 904
  • 1
  • 14
  • 16
0

For me only thing worked is removing the element containing my application name, path and binding info under </system.applicationHost> element in applicationhost file. To be found under C:\Users\yourUsername\Documents\IISExpress\config

Closed the the solution , deleted the bad site element , save the applicationhost file and close. Reopen the application/Website from Visual studio using Admin rights - Rebuilt and Run. Voila... A new port is auto assigned to your application which solves the purpose.

Can also be verified without running-- check the Properties window for the solution and URL will have new port number.

0

In my case I got also this issue from my ASP Core 3.1 projets. I thing that for some reason visual studio ignore the IP/Port setting in the project property and start it on 5000 and 5001. I discovered this while attempting to start my Core 3.1 projects from prompt using dotnet run

And this post helped me How to specify the port an ASP.NET Core application is hosted on?

It suggest to

  • Specify the port in the appsettings.json or maybe appsettings.development.json. (see lower)
  • Close Visual Studio
  • Delete /.vs, /bin, /obj folders
  • Restart Visual Studio.

appsettings.json / appsettings.development.json content

 {   
      /***************************
      "Urls": "http://localhost:49438", <==== HERE
      /***************************/
      
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft": "Warning",
          "Microsoft.Hosting.Lifetime": "Information"
        }
      },
      "AllowedHosts": "*",
      "connectionStrings": { ...  }
    } 
Hugo
  • 2,077
  • 2
  • 28
  • 34
0

Just do these,

  1. stop the running project
  2. close the browser(s)
  3. run the project
saimum720
  • 11
  • 2
-1

The same error was appearing in my Visual Studio 2021. After installing Docker every port was engaged by Kubernetes.WDS.

Simple 2-step solution:

  1. Disable Hyper-V: Control Panel -> Programs and Features -> Turn Windows features on or off. Untick Hyper-V.
  2. Restart the computer.
karel
  • 5,489
  • 46
  • 45
  • 50