简体   繁体   中英

Visual Studio 2015 using Linq in conditional breakpoint

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM