I wrote a data acquisition software that stores the data in several tables and plots this data using the Forms.DataVisualization.Charting.Chart object. To point out special events I use StripLines. The software uses the MyApplication_UnhandledException event to catch all unhandled exception an saves the exception information to a log file.
Unfortunately I got a "NullReferenceException" that seems to have been thrown within a framework method:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.DataVisualization.Charting.StripLine.PaintTitle(ChartGraphics graph, PointF point1, PointF point2)
at System.Windows.Forms.DataVisualization.Charting.StripLine.Paint(ChartGraphics graph, CommonElements common, Boolean drawLinesOnly)
at System.Windows.Forms.DataVisualization.Charting.Axis.PaintStrips(ChartGraphics graph, Boolean selectionMode, Int32 x, Int32 y, Object& obj, Boolean drawLinesOnly)
at System.Windows.Forms.DataVisualization.Charting.Axis.PaintStrips(ChartGraphics graph, Boolean drawLinesOnly)
at System.Windows.Forms.DataVisualization.Charting.ChartArea.Paint(ChartGraphics graph)
at System.Windows.Forms.DataVisualization.Charting.ChartPicture.Paint(Graphics graph, Boolean paintTopLevelElementOnly)
at System.Windows.Forms.DataVisualization.Charting.Chart.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.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)
In principle I know the cause of and how deal with a NullReferenceException, but in this special case I'm a bit at a loss since: - I've not idea which object I should check for being nothing - At what point in code i should do the check - Where to put a Try Catch block since all of the stack is not within my code.
In addition I should mention that the data acquisition runs in a Backgroundworker thread.
Unfortunately the exception is not reproducible / I do not know what that user had done before the exception had been thrown.
I know that these are not the best conditions for debugging but it would be great if some has an idea - what could have caused this exception (e.g. disposed Stripline or charting object) - and how to avoid or at least handle the exception at such a target site?
Thx, Marcus