Visual Studio 2015 using Linq in conditional breakpoint

不想你离开。 提交于 2021-02-05 07:15:26

问题


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.


回答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.



来源:https://stackoverflow.com/questions/42855604/visual-studio-2015-using-linq-in-conditional-breakpoint

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!