Michael Gerbracht
Michael Gerbracht

Reputation: 173

How to find out what caused a NullReferenceException

I am writing a .net program using c# which contains a third-party DataGridView. I managed to s - how the data I want, add/remove columns and rows, react on user selection and so on - everything works fine so far. Now my problem comes when I open the standard OpenFileDialog - it opens as expected and I can also choose files. But when I close it (no matter whether I use the Open or Cancel button) and then try to select columns and rows in the GridView I get a NullReferenceException in System.Windows.Forms.dll. I don't understand why opening and closing a standard dialog causes this problems. I read the following question and it answers but could not comment there - so I had to open a new question:

What is a NullReferenceException and how do I fix it?

I think I understand what a NullReferenceException is, but it would be nice if you could explain me how to find out, which object is causing it. So how can I debug this problem? I do not even know whether there is something wrong in my code or whether it is a bug in the third party extension.

thank you very much!

Edit, 14.10.2013:

I think throw back works but it points me to this line (see arrow):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyProg
{
    static class Program
    {
        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
   --->     Application.Run(new MyProgMain());
        }
    }
}

Unfortunately this does not help me - what does it mean when the Debugger highlights this line?

Upvotes: 2

Views: 2771

Answers (1)

Rauld
Rauld

Reputation: 990

Enable First Chance Exceptions :

On Visual Studio IDE press Esc + Cntl + Alt + E and check the Thrown checkbox for Common Language Runtime Exceptions

Upvotes: 2

Related Questions