Search code examples
c#visual-studiodebugginglambdaconditional-breakpoint

Why can't you have a lambda in a conditional breakpoint in Visual Studio 2013?


Say I have the following method:

public List<List<int>> DoSomething () {
    List<List<int>> result;

    //Do some things

    return result; //Would like to breakpoint here
}

I try to have a conditional breakpoint such as:

result.Any(i => i.Any(j => j < 0))

I get an error saying you cannot have lambda expressions in conditional breakpoints. Why is that?


Solution

  • UPDATE: The feature has been implemented in VS2015! You can now use lambda expressions in conditional breakpoints, watches and in the immediate window.


    The only answer to this question is a boring "because they did not implement the feature". I suppose the cost vs benefit of this feature was simply not worth the development time.

    An alternative to a conditional breakpoint would be to add the following code

    if (result.Any(i => i.Any(j => j < 0)))
        System.Diagnostics.Debugger.Break();
    

    Not very pretty and of course you'll want to remove that once your debugging session is over but it gets the job done.