IEnumerable not null but calling Count() results in Exception
Posted
by Draak
on Stack Overflow
See other posts from Stack Overflow
or by Draak
Published on 2010-06-02T18:56:04Z
Indexed on
2010/06/02
19:04 UTC
Read the original article
Hit count: 233
I have code that's working beautifully on my development machine, but when deployed to the server is throwing null reference exception. So, I can't step through the code, but I've pinned down the culprit. But now I am puzzled. Here's the code. The question is below.
Dim certs = From p In persons _
Select New Certificate( _
p.Value, _
New CertificateData.Seminar(thisEvent.Seminar.Name, _
thisEvent.StartDate.Value, _
thisEvent.EndDate.Value, _
thisEvent.Venue.City, _
thisEvent.Venue.State, _
New CertificateData.Instructor( _
staffMember.Name, _
staffMember.Titles, _
instrSignatPath))) _
With {.CertificateId = p.Key}
lblMessage.Text = CStr(certs Is Nothing)
lblMessage.Text = lblMessage.Text + "<br />" + CStr(certs.Count())
In the code above persons is a dictionary of custom class, and certs is of IEnumerable type. Now here's the quandary.. The first line that sets the label returns False, so certs is not null. But the second line throws an null reference exception. How is this possible?
© Stack Overflow or respective owner