在条件断点中使用Linq的Visual Studio 2015 [英] Visual Studio 2015 using Linq in conditional breakpoint

查看:52
本文介绍了在条件断点中使用Linq的Visual Studio 2015的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在条件断点内使用Linq?

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.

在问题与使用 .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.

推荐答案

此问题是由于未在Visual Studio中启用使用托管的兼容模式选项引起的.

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.

有关如何在Visual Studio中启用此选项的信息,请参见答案.

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

这篇关于在条件断点中使用Linq的Visual Studio 2015的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆