You receive an "Object reference not set to an instance of an object" error message when you try to open a project that contains an inherited user control in Visual Studio .NET or Visual Studio 2005 (894438)



The information in this article applies to:

  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)
  • Microsoft Visual C# 2005, Express Edition
  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual Basic 2005

SYMPTOMS

When you try to open a project that contains an inherited user control, you receive an error message that is similar to the following:
Object reference not set to an instance of an object.
This problem occurs in Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005.

Note This problem occurs when your project contains Web references.

CAUSE

This problem occurs when you save your project with XML attribute characters that are not valid in the project path. Examples of XML attribute characters that are not valid follow:
  • #
  • &
When you try to open the project that contains the inherited user control, Visual Studio .NET 2003 or Visual Studio 2005 scans through the references to find the base type of the control. All references are stored in an XML fragment. The "#" character and the "&" character are valid Windows directory characters. However, they are not valid characters XML attribute characters. This causes Visual Studio .NET 2003 or Visual Studio 2005 to stop scanning through the references when these characters are encountered. Therefore, the base type of the control is not found.

WORKAROUND

To work around this problem, you must avoid using XML attribute characters that are not valid. Do not use the "#" character and the "&" character in the project path.

MORE INFORMATION

Steps to reproduce the problem

  1. Start Visual Studio .NET 2003 or Visual Studio 2005.
  2. On the File menu, click New, click Project, click Visual Basic Projects, and then click Windows Application.

    Note In Visual Studio 2005, click Visual Basic.
  3. Type the following in the Location box, and then click OK.

    Drive_Letter:\My&Directory
  4. In Solution Explorer, right-click Windows Application1, click Add, click Add User Control, click User Control under Templates, and then click Open.
  5. On the View menu, click ToolBox.
  6. Add the TextBox control to the user control in the Designer.
  7. On the Build menu, click Build Solution.
  8. In Solution Explorer, right-click Windows Application1, click Add, click Add Inherited Control, click Inherited User Control under Templates, and then click Open.
  9. In the Inheritance Picker window, click UserControl1 that you created in step 4, and then click OK.
  10. In Solution Explorer, right-click Windows Application1, and then click Add Web Reference.
  11. In the Add Web Reference dialog box, type your WebService in the URL box, and then click Add Reference.
  12. On the File menu, click Close to close all documents.
  13. Try to open UserControl2.vb in the Designer.

    You receive the error message that is mentioned in the "Symptoms" section.

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbvs2002sp1sweep kbtshoot kbbug KB894438 kbAudDeveloper