Why do I get "file is used by another process" errors when I debug within Visual Studio?

To be honest with you, it sounds like a bug in VS2010. For some reason it isn't closing the open handles when the debugger stops. Killing the VS process automatically closes those handles, allowing you to access the file again. As a work around, you might look at unlocker it's free and works exceptionally well. I know that's not a great answer, but it should be faster than restarting VS. You might to consider sending a bug report too...

Unlocker doesn't work on 64-bit OS, LockHunter does though.


Here is how I solved this problem

*I open the project Properties, *select the build tab, *Clear the output path, *and buid(this will create the dll in the root folder) *come back to the output path and select browse(browse to the bin directory to either debug/release)and voila!


As per Error: Cannot access file bin/Debug/… because it is being used by another process answer by TarmoPikaro, sometimes Visual Studio creates multiple msbuild.exe ghost processes, which persist after build. These ghost processes seem to be causing file locks.

Solution 1 - Kill ghost MSBuild.exe's

Killing msbuild.exe's is a one time solution, it needs to be done per build basis.

You can kill the processes as follows mrtumnus:

taskkill /f /im MSBuild.exe

Solution 2 - Disable parallel builds in Visual Studio

You can disable parallel build once and for all:

Tools > Options > Projects and Solutions > Build and Run > "maximum numbers of parallel project builds" - by default it has value of 8, switch it to 1.

Of course builds are bit slower now, but mileage may vary depending on your use case.

This is related to Error: Cannot access file bin/Debug/... because it is being used by another process