The file copied to the Debug folder is automatically deleted when the C # program starts

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

  • Build Action: Content
  • Copy to output directory: always copy

When the design solution is built, the dll is copied to the Debug folder with the .exe generated by Visual Studio successfully. However, when I launched it by double-clicking the generated .exe file from Explorer or "Run" in the VS debugger, the dll suddenly deleted by itself.

Why?

+7
c # dll wpf visual-studio-2012 dllimport
source share
2 answers

If this happens when starting from Explorer, then

  • Your antivirus program removes the DLL when you try to access this

or

  • Your program must have code to delete files in the current directory.
+1
source share

After many attempts, I found some template that could also be a workaround. Suppose we have 3 projects: A, B and C.

  • A depends on B; B depends on C - there is a problem
  • A depends on B and C; B depends on the problem C - disappears

Perhaps this will help someone keep track of the reasons.

0
source share

All Articles