2

Is it possible to use Linq within a conditional breakpoint?

I'm attempting to break when the following condition is true:

parentElement.ChildElements.Any(c => c.Id == 1)

When ever the debugger is hit the following error message is displayed

The debugger is unable to evaluate this expression.

I have tried the following condition in case the issue was related to using .Any()

parentElement.ChildElements.Where(c => c.Id == 1).Count() > 0

This resulted in the same error as above being displayed.

I know a work around would be the following code

#if DEBUG
if(parentElement.ChildElements.Any(c => c.Id == 1))
{
    System.Diagnostics.Debugger.Break();
}
#endif

However, I would ideally not like to make code changes to place a debugger.

Adam T
  • 776
  • 7
  • 18

1 Answers1

1

This issue was caused by the Use Managed Compatibility Mode option not being enabled within Visual Studio.

Once this option was checked the breakpoint performed as expected.

See this answer for how to enable this option within Visual Studio.

Community
  • 1
  • 1
Adam T
  • 776
  • 7
  • 18