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

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


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

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

or

  • There must be code in your program to delete files in the current directory.


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.


I have encountered this, and successfully fixed.

Two things you need to check:

  1. In the project App.xaml, you need to make sure

    • For Application x:Class="..." set to YourWpfProject.App
    • For StartupUri="..." set to the folder your View(MainWindow.xaml) belongs to.
  2. In the beginning of your View(MainWindow.xaml) file, you need to make sure

    • For Windows x:class="..." set to exact namespace your xaml file(View) belongs to. Remember to check clearly if you put your views or viewmodels into a folder under this project.

Now, try your "F5".