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