Original Post
I've written a Windows form application in Visual Studio. For some reason I am getting a NullReference Exception ("Object reference not set to an instance of an object") when I try to close the main form. Otherwise, the debug build works perfectly fine. Why is this? Is there a way to tell which field/variable/parameter is null and causing the exception? Below I've pasted the code where the exception occurs.
//program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Stimulation
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); //NullReferenceException
}
}
}