2
我的代碼在我的開發機器上運行得非常好,但是當部署到服務器時拋出空引用異常。所以,我無法逐句通過代碼,但是我已經鎖定了罪魁禍首。但現在我很困惑。這是代碼。問題在下面。IEnumerable不爲空,但調用Count()結果爲異常
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())
在上面的代碼中,個人是自定義類的字典,certs是IEnumerable類型的。現在,這是窘境。設置標籤的第一行返回False,因此certs不爲null。但第二行引發空引用異常。這怎麼可能?
好主意!..... – Marcel 2010-06-02 19:09:07
謝謝。你是對的。 thisEvent.Venue爲空 – Antony 2010-06-02 20:28:08
@Draak,感謝您的反饋。延遲執行通常會導致事情以不同於程序員最初預期的方式發生,因此我總是問自己,在處理LINQ問題時延遲執行是否會導致您的麻煩。 – Lucero 2010-06-02 20:43:29