I’m getting the following exception while redrawing my DataGridView control:
Unhandled exception : Odwołanie do obiektu nie zostało ustawione na wystąpienie obiektu.
Source : System.Windows.Forms
Stack : w System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle boundingRect, Rectangle clipRect, Boolean singleHorizontalBorderAdded)
w System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle gridBounds, Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)
w System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)
w System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
w System.Windows.Forms.Control.WmPaint(Message& m)
w System.Windows.Forms.Control.WndProc(Message& m)
w System.Windows.Forms.DataGridView.WndProc(Message& m)
w System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
w System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
w System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Which basically says that
Object reference is not set to an instance of an object.
The weird thing is that is seems to be connected with domain user permissions somehow, because on my privileged account (not Administrator, just more privileged settings) it works, and on “normal” user account it crashes every time. I don’t know the difference between those accounts, they were not configured by me and I cannot access AD configuration. Another thing is that .NET framework versions /updates on both machines are the same.
Is it possible there is some kind of limit set for a number of threads per application, per user?
Any tips what I can check are welcome.
Your call stack shows no evidence of this code running on the UI thread. No sign of Application.Run(). That’s unhealthy, DataGridView is not a thread-safe control. None of them are. Such code can malfunction in very unpredictable ways, a NullReferenceException is certainly possible.
Review your code for any place where you might have started a worker thread and are either updating DGV properties directly. Or more commonly, updating data that is bound to the DGV. You’ll have to unbind to prevent the DGV update from running on the worker thread, re-bind on the UI thread. Use a BackgroundWorker to make that easier.