I've had this application running for over a year now with no issue and all of a sudden it's throwing an error on the code below. I have no idea why it started doing this. This is a production application.
I've tried a few of the fixes found on the net but nothing is working.
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());
}
Error message below...
System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object.
Source=PeakViewRoofing StackTrace: at PeakViewRoofing.LeadDetail.LoadLead() in C:\Users\Matthew\Source\Repos\Peak Net V1\Source\PeakViewRoofing\LeadDetail.cs:line 251 at PeakViewRoofing.LeadDetail.LeadDetail_Load(Object sender, EventArgs e) in C:\Users\Matthew\Source\Repos\Peak Net V1\Source\PeakViewRoofing\LeadDetail.cs:line 156 at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
User contributions licensed under CC BY-SA 3.0