I have encountered a bizarre issue trying to step into a method called from within a Linq query (although I also experience the problem when using a Linq expression). The code compiles, AND it appears to work (I get the outcome I was expecting).
IEnumerable<TagBuilder> theOutcome = from r in resultSet
select GetTableDataRow(null);
OR
IEnumerable<TagBuilder> theOutcome = resultSet.Select(r => GetTableDataRow(null));
The method being called is defined as follows:
private static TagBuilder GetTableDataRow(IEnumerable<object> rowData)
{
TagBuilder tr = new TagBuilder("tr");
return tr;
}
The resultSet
variable is an IPagedList
that contains two items.
The variable theOutcome
ends up holding two TagBuilder
instances as expected.
However, I cannot then step into GetTableDataRow()
, even if I put a breakpoint on or before the Linq query in question. If I put a breakpoint IN the GetTableDataRow()
method, it never hits that either.
I'm completely stumped. Can anyone help? Code is obviously very simple right now, but I'll NEED to step through the contents of that method with the debugger as I develop it.
.ToArray()
onto the end of theSelect
does allow me to step into the method! I had a look at the article you linked but I don't really understand the relationship of lazy evaluation to this issue, in the sense that isn't the Linq being evaluated because I'm getting output intotheOutcome
variable? It looks like you've edited it out now so perhaps it was not relevant after all. I would be interested in knowing what's going on though. – Diffractometer