I have following code:
IEnumerable<Example> examples = someCollection.Where(x => x.IsExample);
object result = examples.SingleOrDefault() ?? (object)DBNull.Value;
return result;
My intention is to use a conditional breakpoint for line 2 to stop execution, if the condition examples.Count() != 1
is met.
Visual Studo returns an error message saying The condition for a breakpoint failed to execute.[...] The error returned was 'The expression cannot be evaluated. [...]'
However, when I added the line var count = examples.Count()
and changed the condition of my breakpoint to count != 1
it worked fine.
Is this some kind of bug or is there a reasonable explanation for this error?