Use Debug mode, Release mode optimization may cause this wrong tracing.
Disable Optimization in Configuration:
In your project settings, make sure that you are compiling in Debug mode while developing. Debug builds usually contain more accurate debugging information. In Release mode, compilers apply various optimizations that can make line numbers less precise.
But if you insist on using Release i guess
Use PDB Symbol Files:
Ensure that your project generates PDB (Program Database) symbol files. PDB files contain debugging information that allows the debugger to map machine code back to source code lines more accurately.
Avoid Inlining and Compiler Optimizations:
Some code optimizations like inlining can make it difficult for the debugger to accurately trace the execution path. You can use the [MethodImpl(MethodImplOptions.NoInlining)] attribute on methods that you want to avoid inlining. As described here
Update to at least .NET 6:
.NET 6 has improvements in debugging and performance, so consider upgrading all project to a >=6 version to see if it resolves your issue.
Adjust Debugging Settings in IDE:
Check your IDE's settings. In Visual Studio check "Suppress JIT optimization on module load." This can help with accurate debugging.