FIX: You may receive an error message when you open a form in Design view in Visual Studio .NET (893709)
The information in this article applies to:
- Microsoft Visual Studio .NET (2003), Professional Edition
- Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2003), Academic Edition
- Microsoft Visual Studio .NET (2002), Professional Edition SP1
- Microsoft Visual Studio .NET (2002), Enterprise Architect Edition SP1
- Microsoft Visual Studio .NET (2002), Enterprise Developer Edition SP1
- Microsoft Visual Studio .NET (2002), Professional Edition
- Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2002), Academic Edition
SYMPTOMSIn Microsoft Visual Studio .NET, when you open a form in Design view, you may receive one of the following error
messages even though the project builds and runs correctly: An exception occurred while trying to create an instance of
CustomType. The exception was "Constructor on type
CustomType not found." Object reference not set to an instance of an
object. CAUSEThis issue may occur if you use inheritance and one of the following conditions is true: - You have a
base form that does not contain a default constructor. A default constructor is a constructor that
does not expect parameters.
- The Form_Load event is used to set values of objects
that are contained in the form.
At design time, the inherited form instantiates the base form by using the default constructor. If no default constructor exists, Visual Studio .NET cannot display the inherited form in Design view, and you receive an error message. When the base form is instantiated, the Form_Load event
is also called. Objects that are referenced in this event may return the "Object
reference no set to an instance of an object" error message when you inherit the base
form. RESOLUTIONTo resolve this issue, provide a default constructor for
the base form. This constructor should not take any parameters. The default
constructor must contain a call to the InitializedComponent method of the
base form.
Note The DesignMode property of the Form object determines whether a
form is in Design view or not. This property only lets you run code when a form is not in Design view.
Modification Type: | Major | Last Reviewed: | 7/19/2005 |
---|
Keywords: | kbBug kbfix KB893709 kbAudDeveloper |
---|
|