I've got this error while compiling a big c# solution in Visual Studio 2010.
Each time after compilation I had to delete obj folder of one the projects used by this solution. Otherwise I got the following error:
Could not write to output file '...\obj\Debug\Foo.Bar.dll'
The process cannot access the file because it is being used by another process
I've was looking for a solution all over the Internet and actually found/tried few of them.
For example : a lot of people on dev forums were suggesting not to start the compilation while UserControl (in some other sources From) designer is opened.
Some other people used pre-build scripts for obj folder removal, this particular solution is acceptable, but if the issued project is a widely used library its recompilation will cause recompilation of "parent" projects.
Finally I've discovered a solution for this VS2010 (SP1 too) "bug" and I want to share it with stackoverflow users.
In my case the problem was that csproj file was SELF-REFERENCING the locked '...\obj\Debug\Foo.Bar.dll'
file. Crazy I know.
So I solved this annoying issue by removing the following line from .csproj
file:
<Reference Include="Foo.Bar">
<HintPath>obj\Debug\Foo.Bar.dll</HintPath>
</Reference>
I initially found another solution to the problem as VS seems to lock the assembly in the obj\debug folder. I added a pre-build script to the project which fixed my problem.
del "$(ProjectDir)obj\*.*" /S /F /Q
After seeing the answer given by Salaros, that was indeed the problem. I created a new usercontrol that uses a Server control from another project. For some reason VS sometimes creates a self-references to itself when you view the usercontrol in design mode. Even removing the self-reference fixes it until VS thinks its time to add the reference again. Haven't found an exact pattern for that part.
PS: I'm using vs2012
In my case for me somehow the exe file was missing from release. Not sure how this happened. I replace it with a copy from debug and all was fine. I should have checked this sooner but never thought that the file would just turn up missing.
This problem happened to me when I:
- Opened Visual Studio
- Ran debug
- Went to C: and used system cleanup
If you try to build again, you will find this error.
Solution:
- Close Visual Studio
- Do system cleanup
- Restart your computer
- Open Visual Studio as administrator
- Choose your project
- Clean
- Rebuild