Controls that are built by using Visual Studio .NET 2003 fail to load in Visual Studio .NET 2002 (820649)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

SYMPTOMS

You can create and then build a Microsoft Windows control by using Microsoft Visual Studio .NET 2003. However, when you add the Windows control to Microsoft Visual Studio .NET 2002, you may receive the following error message:
There are no components in '<Project path>\bin\TestCtrl.dll' that can be placed on the toolbox.
When you try to add the Windows control programmatically in Visual Studio .NET 2002, you may receive the following error message:
Attempted to store an element of the incorrect type into the array.

CAUSE

The types of the base class of USER control and of System.Windows.Forms.UserControl are different in .NET Framework version 1.0 and in .NET Framework version 1.1. Therefore, the runtime displays an error when you try to load a control that was created in Visual Studio .NET 2003 and that you then want to use in Visual Studio .NET 2002.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Problem

Create the Control

  1. Run Visual Studio .NET 2003.
  2. Point to New on the File menu and then click Project.
  3. Under the Project types section, click Visual Basic Projects. Under the Templates section, click Windows Control Library.
  4. In the New Project dialog box, type TestCtrl in the Name text box. Type C:\TestCtrl in the Location text box.
  5. Click OK.

    By default, UserControl1 is created.
  6. On the Build menu, click Build Solution.

Try to Add the Control by Using the UI

  1. Run Visual Studio .NET 2002.
  2. Point to New on the File menu and then click Project.
  3. Under the Project types section, click Visual Basic Projects. Under the Templates section, click Windows Application.

    By default, Form1 is created.
  4. Right-click Toolbox and then click Customize Toolbox.
  5. In the Customize Toolbox dialog box, click the .NET Framework Components tab.
  6. Click Browse and then select the TestCtrl.dll file that is located in the C:\TestCtrl\TestCtrl\bin directory.
  7. You may receive the following error message:
    There are no components in 'C:\TestCtrl\TestCtrl\bin\TestCtrl.dll' that can be placed on the toolbox.

Try to Add the Control by Using Code

  1. Run Visual Studio .NET 2002.
  2. Point to New on the File menu and then click Project.
  3. Under the Project types section, click Visual Basic Projects. Under the Templates section, click Windows Application.

    By default, Form1 is created.
  4. On the View menu, click Solution Explorer.
  5. Right-click the Solution Explorer window and then click Add Reference.
  6. In the Add Reference dialog box, click Browse and then select the TestCtrl.dll file that is located in the C:\TestCtrl\TestCtrl\bin directory.
  7. In the Toolbox window, double-click the Button control to add Button1 to Form1.
  8. On Form1, double-click Button1 to display the Code window.
  9. Add the following code to the Button1_Click event handler:
    Dim MyCtrl As New TestCtrl.UserControl1()
            Me.Controls.Add(MyCtrl)
  10. On the Build menu, click Build Solution.
  11. On the Debug menu, click Start.
  12. When Form1 appears, click Button1.
  13. You may receive the following error message:
    Attempted to store an element of the incorrect type into the array.

REFERENCES

For more information about Component Authoring, visit the following Microsoft Web site: http://msdn.microsoft.com/library/en-us/xpehelp/html/weconComponentAuthoring.asp

Modification Type:MinorLast Reviewed:2/3/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kberrmsg kbWindowsForms kbControl kbprb KB820649 kbAudDeveloper