.NET Developers often face this issue when they use the existing project or add existing project into another new solution. In my case, I faced this issue while adding existing project into another solution. Whenever, I run the project, I get this error message.
The exact error is shown below:
Failed to register URL “http://localhost:49239/” for site “ProjectName” application “/”. Error description: The process cannot access the file because it is being used by another process.
We can also face issue like as shown.
Both these error are related with same.
Reason for this error.
The main cause for this error is the port is already being used by another project.
The error code 0x80070020 means ERROR_SHARING_VIOLATION. In other words, our IIS Express or IIS port that it is attempting to listen on is being used by another process.
We can resolve this issue several ways.
Solution 1: You can change the port number.
- Right click on the project and select Unload Project
- Again right click the project and select Edit the project, ProjectName.csproj
- Search for these three lines
<DevelopmentServerPort>0</DevelopmentServerPort> <DevelopmentServerVPath>/</DevelopmentServerVPath> <IISUrl>http://localhost:62940/</IISUrl>
4. Remove these 3 lines
5. Save and reload the project.
After doing this, your project will be assigned with new port which is not in use.
Solution 2: You can check and verify the port which are in used.
We can use netstat to find the application using the port as shown.
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.
Output of this command.
Then you can identify the application using same port and modify accordingly with solution 1.