Debugger not stopping at breakpoint when there's an exception within a LINQ lambda.
Here's a quick repro:
try { new[]{0}.Select<int, int>(_ => { throw new NotImplementedException(); }).ToList(); } catch (Exception ex) { throw; // breakpoint here }
When the breakpoint is set, execution stops within the lambda causing some confusion.
In my particular case, the catch block of the intended breakpoint has some needed context for debugging and is making it unnecessarily difficult to track.
Comments
This might not be a LINQPad specific problem, but rather what line the debugger is reporting. Inserting
Debugger.Break()
at the point I wanted the original breakpoint causes the same behavior.This is a bug in the CLR. It was supposed to be fixed in .NET 6, but the target has now moved to .NET 7:
https://github.com/dotnet/runtime/issues/44986
It might help to get extra feedback in this report.
This is now fixed in the 7.4.6 beta.