Visual Studio 2015 locks DLL during debugging

2019-03-18 13:58发布

问题:

I have 3 C# projects A, B, and C. Both A and B reference C. The references to C from A and B are set to "Copy Local" implying that after C is built to C.dll (in the output directory of C), it is copied to the output directory of A or B (whichever is being compiled)

I have 2 solutions, SA and SB. SA contains A and C and SB contains B and C. I launch 2 instance's of Visual Studio 2015. I open SA in one instance and SB in the other.

I am finding that if I Start Debugging (F5) A from SA, and then (while A is still debugging), make a change to C from SB and attempt to compile SB, I receive a compile error stating that C.dll can not be over-written because it is in use by another process (the instance of devenv.exe which is running SA).

This does not make sense to me because after compiling C to C.dll and copying to the output directory of A, Visual Studio should release the lock on the file.

I have verified (via the Modules window in SA) that the version of C.dll loaded is the one which has been copied to the output directory of A.

This started occurring yesterday when I began using Visual Studio 2015 (instead of Visual Studio 2013).

Does anyone have any ideas? My current solution is to run SA via CTRL-F5 (start without debugging), but this becomes annoying when I want to run SA and SB in debug mode simultaneously.

Thanks.

UPDATE

I did some research into why the "Edit and Continue" feature could cause the described behavior, and according to this page https://msdn.microsoft.com/en-us/library/ms164926.aspx> Edit and Continue allows one to make source code modifications while in a debugging session and have the results take effect without stopping debugging, recompiling, and restarting the debugging session (what a gnarly problem that must have been). With that feature enabled, Visual Studio might be required to recompile any dependent DLL's at any time which explains the lock.

回答1:

I had the same problem. I changed my VS2015 settings and it seems the problem is gone:

  • disabled Options\Debugging\Edit and continue
  • -Options\Sourcecodemanagement from TFS to none-
  • -disabled Options\Debugging\Diagnostictools while debugging-

Not sure wich one caused the locking, but i suspect the diagnostictools wich I did not have in VS2013. (The settings names I translated from German to english, don't know if it is exactly how they are called in english VS version.)

Edit: As researched by Shea it was the Edit-And-Continue feature that locked the DLL.



回答2:

in my case this was "Panda free Antivirus" Who was watching on the dll of the "C" project and this caused the error: "the process cannot access the file because it is being used by another process"



回答3:

I had the same problem and none of the other recommended solutions I came across while searching the interwebs worked for me. Finally after "repairing" Visual Studio 2015 Enterprise, I tried launching Visual Studio in safe mode: devenv.exe /SafeMode

In safe mode I was able to finally build my solution, and when I started again without the switch, I was prepared to shut off extensions one by one until I found which one was the culprit. Luckily that was unnecessary and subsequent builds went off without a hitch.



回答4:

In my case, the .pdb file was locked. This is not the same as the .exe getting locked as it should be when debugging.

Assuming it's just the .pdb, simply move it to a new folder (I dragged and dropped). Oddly enough, it cannot be deleted, but it can most certainly be moved! Once the .pdb file was gone, the assembly was able to compile again.

The alternative solution (and probably the least convenient) involves closing out of the project entirely, then opening it again (the .pdb file magically unlocks!).

Edit: After happening a second time, moving the file did not work; it appears restarting the project is the only reliable way to go.