Microsoft KB Archive/820649

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

Article ID: 820649

Article Last Modified on 1/12/2007

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-





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 '\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.



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.
 * 1) On the Build menu, click Build Solution.

Try to Add the Control by Using the UI
 Run Visual Studio .NET 2002. Point to New on the File menu and then click Project. Under the Project types section, click Visual Basic Projects. Under the Templates section, click Windows Application.

By default, Form1 is created. Right-click Toolbox and then click Customize Toolbox. In the Customize Toolbox dialog box, click the .NET Framework Components tab.</li> Click Browse and then select the TestCtrl.dll file that is located in the C:\TestCtrl\TestCtrl\bin directory.</li> 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.

</li></ol>

Try to Add the Control by Using Code
<ol> Run Visual Studio .NET 2002.</li> Point to New on the File menu and then click Project.</li> Under the Project types section, click Visual Basic Projects. Under the Templates section, click Windows Application.

By default, Form1 is created.</li> On the View menu, click Solution Explorer.</li> Right-click the Solution Explorer window and then click Add Reference.</li> 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.</li> In the Toolbox window, double-click the Button control to add Button1 to Form1.</li> On Form1, double-click Button1 to display the Code window.</li>  Add the following code to the Button1_Click event handler: Dim MyCtrl As New TestCtrl.UserControl1 Me.Controls.Add(MyCtrl) </li> On the Build menu, click Build Solution.</li> On the Debug menu, click Start.</li> When Form1 appears, click Button1.</li> You may receive the following error message:

Attempted to store an element of the incorrect type into the array.

</li></ol>

<div class="references_section">