I have developed a small WinForm application with C#. I have released this app for years, and a lot of users use it on many different Windows system, Windows XP, Vista, 7, 8, 32bit and 64bit.
But a few days ago one user reported a crash when launching application on a Windows 7 64bit machine. Because I can't reproduce the error on my side so I sent him the debug version which can output log information.
Now I have located the line which fails on
this.Controls.Add(this.myUserControl);
It's a line which Visual Studio generated from the Forms Designer. "this.myUserControl" is an instance of an User Control. This User Control is built in this project, and not includes any external components. Just built with some standard UI controls. The .NET error information is
"System.NullReferenceException: Object reference not set to an instance of an object."
I have added code to test whether the this.myUserControl is null before adding it to controls, it's definitely not null.
I have tried a lot of methods, like using corflags.exe to force it running in 32bit mode or changing the build target framework to 3.5 (before it's 2.0)
Nothing changes. It always crashes on that line.
I have tested this app on Windows 7 64bit before I released it, and this app have a lot of users using it on Windows 7 64bit. So I think I should not change any code. But I don't have any direction on how to solve this problem.
Should I tell the user to reinstall Windows or repair .Net Framework? Did anyone meet this error on Windows 7 64bit?
English is not my native language so sorry for my English.
The code related to the user control, all these codes is generated from the Forms Designer:
private MyUserControl myUserControl;
this.myUserControl = new ProjectNameSpace.MyUserControl();
this.myUserControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.myUserControl.Location = new System.Drawing.Point(12, 80);
this.myUserControl.Name = "myUserControl";
this.myUserControl.Size = new System.Drawing.Size(775, 412);
this.myUserControl.TabIndex = 2;
this.myUserControl.Resize += new System.EventHandler(this.myUserControl_Resize);
this.Controls.Add(this.myUserControl);
UserControlalso this.Controls what does it refer toPanel, ListView, etc..Add()method (.Net code), or on that actual line? (your code)