Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2015 locks DLL during debugging

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.

like image 232
Shea Avatar asked Aug 21 '15 20:08

Shea


People also ask

How do I debug DLL in Visual Studio?

Debug from the DLL project Set breakpoints in the DLL project. Right-click the DLL project and choose Set as Startup Project. Make sure the Solutions Configuration field is set to Debug. Press F5, click the green Start arrow, or select Debug > Start Debugging.

What is use managed compatibility mode?

Use Managed Compatibility Mode: Replaces the default debugging engine with a legacy version to enable these scenarios: You are using a . NET language other than C#, Visual Basic, or F# that provides its own Expression Evaluator (this includes C++/CLI).


2 Answers

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.

like image 68
Matmok Avatar answered Nov 02 '22 00:11

Matmok


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"

like image 38
Developer Avatar answered Nov 02 '22 01:11

Developer