Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2008 locks dll in bin folder and doesn't let go of it

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.

like image 745
Adrian Grigore Avatar asked Jul 21 '09 21:07

Adrian Grigore


3 Answers

I've faced the same problem before. Process Explorer is able to delete the handle.

like image 86
Mark P Neyer Avatar answered Nov 20 '22 04:11

Mark P Neyer


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.

like image 36
Randolpho Avatar answered Nov 20 '22 04:11

Randolpho


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);

like image 41
Alex O. Avatar answered Nov 20 '22 04:11

Alex O.