I have an issue debugging my C# code in Visual Studio 2015.
I want to add a simple expression into a breakpoint,
So I added hierarchyRelation != null as condition. That is a local variable of the method I am debugging, and it exists.
However, in runtime I get the following error
"The condition for a breakpoint failed to execute. The condition was "hierarchyRelation != null". The error returned was "The breakpoint condition must evaluate to a boolean operation". Click OK to stop at this breakpoint.
Actually, the condition was more complex, but this is the simplest case that reproduces the problem. I tried variants, and even comparing properties of this variable and it always fails the same.
If I try a constant condition, like 1 != 2 or 1 = 1 it works fine. Is there any issue ? The closest related question I found was this, but it was in vb code. Its solution was to add a debug method directly in the code. Although I can do that, I want to know why is this not working.
The method 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;
}
I am adding the breakpoint in the first line inside the foreach
