I am working on a solution consisting of 8 .NET projects. Since I am practicing TDD, I have to re-compile my solution very often. Lately I have been getting the following error about every second time when trying to compile:
Error 2 Unable to copy file "obj\Debug\Zeiterfassung.Tests.dll" to "bin\Debug\Zeiterfassung.Tests.dll". The process cannot access the file 'bin\Debug\Zeiterfassung.Tests.dll' because it is being used by another process.
Zeiterfassung.Tests.dll is the dll generated by one of my projects (it's the unit testing project). It's always this dll that cannot be copied and causes the error. Everything else works fine 100% of the time.
In about 9/10 times I can "solve" the problem by recompiling my solution again. But when the problem is getting really bad, the project just won't compile successfully no matter how often I try and I have to restart the IDE.
I used microsoft's handle.exe to ascertain which process is locking the DLL and it is devenv.exe. I also tried deleting the DLL by hand and it really can't be deleted until I restart the IDE.
Last but not least, I tried adding <GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>
to my project as suggested in another forum, but this did not help.
Please help! This problem is really starting to drive me nuts.
Edit: I might also add that I made sure my unit tests are finished when this problem occurrs. Still, the dll remains locked. I am running my tests via the Resharper unit test explorer.
I've faced the same problem before. Process Explorer is able to delete the handle.
The most likely problem is a threading issue. You probably had an itinerant thread that is still executing, and it has the reference to the .DLL.
This worked for me: 1) Create new folder outside of the Project (c:\Debug); 2) Right click your Project and select Properties; 3) Locate Build tab; 4) Navigate to Output section in the Build tab (last one in VS2010); 5) Click Browse button and select your new c:\Debug location as an output directory; 6) Save all changes; 7) Build (F6);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With