Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File copied to Debug folder is automatically deleted when the C# program launches

I am using Visual Studio 2012 to build a WPF program. There is a DLL compiled from C that I use DllImport to call. The Dll is added in the project and marked as

  • Build Action: Content
  • Copy to Output Directory: Copy always

When the project solution is built the dll is copied to Debug folder with the .exe generated by Visual Studio successfully. However, when i run it, either by double click the generated .exe from File Explorer or "Run" in the VS debugger, the dll suddenly gets deleted by itself.

Why?

like image 440
palazzo train Avatar asked Jan 11 '16 07:01

palazzo train


2 Answers

If it does this when running from File Explorer, then either

  • Your anti-virus program is deleting the dll when you try to access it

or

  • There must be code in your program to delete files in the current directory.
like image 166
sgmoore Avatar answered Oct 26 '22 00:10

sgmoore


After many tries I've found some pattern which can be also a workaround. Assume we have 3 projects, A, B and C.

  1. A depends on B; B depends on C - problem exists
  2. A depends on B and C; B depends on C - problem disappears

Maybe it'd help someone to track the reasons.

like image 26
matz Avatar answered Oct 26 '22 00:10

matz