3

I am trying to debug a quite simple application in Visual Studio, but breakpoints are not working. When an exception occurs and I click on some methods I'll get error messages like

Source not found

and

Source file is different

and

The breakpoint will currently not be hit. The source file is different from the original version.

There are only 2 ways for me to make debugging work again:

  • restart Visual Studio

  • unload the project and reload it

Both has not been needed during the last 18 years of my C# development carreer. How can I get Visual Studio to compile and debug just as it should?

The affected file in this case is App.xaml.cs in a relatively small project. I have this problem with other files in almost all solutions I work with, so this looks much like a Visual Studio problem to me.

I don't want to disable Checksums or similar in order to make breakpoints work. I just want the thing to work - there's no reason that the code and the binary are different (see below).

I am using Visual Studio 2019 Enterprise 16.11.9 at the time of posting this question. Updating to 16.11.10 did not help either (same problem a day later).

For reference, here's what I tried as an alternative to restarting or unloading:

  • rebuilding of the solution - it rebuilds successfully but doesn't affect debugging

    Rebuild started...
    1>------ Rebuild All started: Project: MetalPanda, Configuration: Release Any CPU  ------
    1>  MetalPanda -> D:\...\MetalPanda\bin\Release\MetalPanda.exe
    2>------ Rebuild All started: Project: MetalPanda.Test, Configuration: Release Any CPU ------
    2>  MetalPanda.Test -> D:\...\MetalPanda.Test\bin\Release\MetalPanda.Test.dll
    ========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========
    
  • clean + rebuild of the solution lie OP of this question - it rebuilds successfully but doesn't affect debugging

    Clean started...
    1>------ Clean started: Project: MetalPanda.Test, Configuration: Release Any CPU ------
    2>------ Clean started: Project: MetalPanda, Configuration: Release Any CPU ------
    ========== Clean: 2 succeeded, 0 failed, 0 skipped ==========
    
  • according this answer I also made sure that "Build" is checked in all configurations

    Build is checked

  • according the same answer I made sure I unchecked "only build startup project and dependencies on run" (although that should be sufficient, because it is my startup project)

    Build only startup project and dependencies

  • checking whether some process changes the file after it has been compiled. I am using Process Monitor with the filter Path contains App.xaml.cs but I can't see any write access.

    Process Monitor result

  • I have staged my changes in Git in order to be able to notice any differences in the file. There are no differences.

  • I have added an extra line Debug.WriteLine("Just for StackOverflow"); in order to check whether that actually gets compiled into the code. I can see its output, so it is compiled and the source code matches the binary

    [...]
    'MetalPanda.exe' (CLR v4.0.30319: MetalPanda.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Symbols loaded.
    Just for StackOverflow
    'MetalPanda.exe' (CLR v4.0.30319: MetalPanda.exe): Loaded 'D:\...\MetalPanda\bin\Debug\Newtonsoft.Json.dll'. 
    [...]
    
  • I rebuilt each individual project of the solution suggested in this answer. (I only have 2: the startup project and the unit tests). Each project builds successfully, but that has no effect on debugging.

  • I deleted both bin and obj subfolders as suggested in this answer. Deleting them was possible, which also proves that the executable is not running otherwise, preventing a rebuild.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222

0 Answers0