【发布时间】:2018-07-12 16:08:13
【问题描述】:
我在 Visual Studio 2015 中调试 C# 代码时遇到问题。
我想在断点中添加一个简单的表达式,
所以我添加了hierarchyRelation != null 作为条件。那是我正在调试的方法的局部变量,它存在。
但是,在运行时出现以下错误
"断点的条件未能执行。条件是 “层次关系!= null”。返回的错误是“断点 条件必须计算为布尔运算”。单击“确定”停止 这个断点。
实际上,情况更复杂,但这是重现问题的最简单情况。我尝试了变体,甚至比较了这个变量的属性,但它总是失败。
如果我尝试一个恒定的条件,比如1 != 2 或1 = 1,它可以正常工作。有什么问题吗?我找到的最接近的相关问题是this,但它在vb code。它的解决方案是直接在代码中添加调试方法。虽然我可以这样做,但我想知道为什么这不起作用。
方法代码
private HierarchyNodeDto GetNodeTreeThatContainsText<TRollup, TLeaf, THierarchyRelation>(HierarchyNodeDto root, string text, PreFilter preFilter, Func<TLeaf, bool> leafContainsTextFunc, bool parentContainsText) where TRollup: HierarchyNodeDto where TLeaf: HierarchyNodeDto {
dynamic rootNode = root as TRollup;
if (rootNode != null) {
if (rootNode.Nodes == null) {
return null;
}
var childNodesWithText = new List<THierarchyRelation>();
foreach (var hierarchyRelation in rootNode.Nodes) {
var isLeaf = hierarchyRelation.Node.GetType() == typeof(TransactionTypeHierarchyLeafDto) || hierarchyRelation.Node.GetType() == typeof(AccountHierarchyLeafDto);
if (!isLeaf && hierarchyRelation.Node.Name != null && hierarchyRelation.Node.Name.ToLower().Contains(text) && preFilter != PreFilter.Leafs) {
childNodesWithText.Add(hierarchyRelation);
continue;
}
var subtreeThatContainsText = this.GetNodeTreeThatContainsText<TRollup, TLeaf, THierarchyRelation>(hierarchyRelation.Node, text, preFilter, leafContainsTextFunc, rootNode.Name.ToLower().Contains(text));
if (subtreeThatContainsText == null) {
continue;
}
hierarchyRelation.Node = subtreeThatContainsText;
childNodesWithText.Add(hierarchyRelation);
}
rootNode.Nodes = childNodesWithText;
if (rootNode.Nodes.Count > 0 || (rootNode.Name.ToLower().Contains(text) && preFilter != PreFilter.Leafs)) {
return rootNode;
}
return null;
}
var rootLeaf = root as TLeaf;
return rootLeaf != null && ((leafContainsTextFunc.Invoke(rootLeaf) && preFilter != PreFilter.Nodes) || (parentContainsText && preFilter != PreFilter.Leafs)) ? rootLeaf : null;
}
我在foreach 内的第一行添加断点
【问题讨论】:
-
VS2015 调试器确实有很多错误,但是当我尝试它时,它看起来并没有损坏。确保安装了更新,至少安装到更新 2。可能的解决方法是避免使用工具 > 选项 > 调试 > 常规、“使用托管兼容模式”和“使用旧版 C# 和 VB.NET 表达式评估器”的错误。
-
我已经安装了版本 14.0.25431.01 更新 3。将尝试检查兼容模式
标签: c# debugging visual-studio-2015 visual-studio-debugging