我已经将该应用程序运行了一年多,没有任何问题,突然之间,它在下面的代码上引发了错误。我不知道为什么它开始这样做。这是一个生产应用程序。
我已经尝试了一些在网上找到的修复程序,但是没有任何作用。
private void LoadLead()
{
DataClasses1DataContext context = new DataClasses1DataContext();
var lead = (from l in context.Leads where (l.ClientID == ClientID && l.Id == LeadId) orderby l.CustomerName select l).FirstOrDefault();
if (lead == null)
{
lead = (from l in context.Leads where (l.Id == LeadId) orderby l.CustomerName select l).FirstOrDefault();
//Error is being thrown on the below line.
ClientID = Utils.iNullSafe(lead.ClientID.ToString());
}
下面的错误消息...
System.NullReferenceException HResult = 0x80004003消息=对象 引用未设置为对象的实例。
Source = PeakViewRoofing StackTrace:位于 PeakViewRoofing.LeadDetail.LoadLead()在 C:\ Users \ Matthew \ Source \ Repos \ Peak Net V1 \ Source \ PeakViewRoofing \ LeadDetail.cs:251行位于 PeakViewRoofing.LeadDetail.LeadDetail_Load(对象发送者,EventArgs e) 在C:\ Users \ Matthew \ Source \ Repos \ Peak Net V1 \ Source \ PeakViewRoofing \ LeadDetail.cs:第156行位于 System.EventHandler.Invoke(Object sender,EventArgs e)位于 System.Windows.Forms.Form.OnLoad(EventArgs e)位于 System.Windows.Forms.Form.OnCreateControl()在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
在System.Windows.Forms.Control.CreateControl()在 System.Windows.Forms.Control.WmShowWindow(Message&m)在 System.Windows.Forms.Control.WndProc(Message&m)位于 System.Windows.Forms.ScrollableControl.WndProc(Message&m)位于 System.Windows.Forms.Form.WmShowWindow(Message&m)在 System.Windows.Forms.Form.WndProc(Message&m)位于 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m) 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)