I came across this situation in Visual Studio 2019. The reason for this behavior was the "Optimize code" flag on the Build tab. Some information about this can be found here:
https://learn.microsoft.com/en-us/visualstudio/debugger/project-settings-for-csharp-debug-configurations
Unless a bug appears only in optimized code, leave this setting deselected for Debug builds. Optimized code is harder to debug, because instructions do not correspond directly to statements in the source code.