Microsoft KB Archive/818220

= The ActiveX user control is not visible in the Form Designer when you reopen an existing project =

Article ID: 818220

Article Last Modified on 12/3/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft .NET Framework 2.0

-



SYMPTOMS
When you reopen an existing Windows application in Visual Studio .NET or Visual Studio 2005, a previously visible ActiveX user control may not be visible in the Windows Form Designer. Also, when you try to compile the project, you may receive errors similar to the following:

Type 'AxProject1.AxTestControl' is not defined.

The referenced component 'AxProject1' could not be found. A .NET assembly wrapper for the dependent type library 'Project1' could not be found.



CAUSE
When you add an ActiveX user control to a Visual Studio .NET or Visual Studio 2005 project, Visual Studio .NET or Visual Studio 2005 internally starts the Windows Forms ActiveX Control Importer tool (Aximp.exe). Aximp.exe converts the type library of the ActiveX user control, and it generates the following two files:
 * A common language runtime proxy for COM types.
 * A Windows Forms proxy for the ActiveX user control.

These two proxy files have information that relates to the existing ActiveX user control.

When you add a public member to the existing ActiveX user control, such as an event, method, or property, and then you recompile the ActiveX user control, one or more public members are added to the interface of the ActiveX user control. However, the common language runtime proxy file is not updated with this new information. Therefore, the ActiveX user control is not generated correctly in the Windows Form Designer, the corresponding Windows Forms proxy is not updated either, and the behavior discussed in the &quot;Symptoms&quot; section of this article occurs.

Note On the Properties dialog box of the project, you can click the Component tab, and then select the Binary Compatibility option before you recompile the existing ActiveX user control in Microsoft Visual Basic 6.0. In this case, although the common language runtime proxy is updated, the Windows Forms proxy is not updated. This results in the same symptoms.



WORKAROUND
To work around this problem, remove the existing references of the ActiveX user control, and then add the updated references again. To do this, follow one of the following methods.

Method 1

 * 1) In Solution Explorer, under References, right-click AxProject1, and then click Remove.
 * 2) Under References, right-click Project1, and then click Remove.
 * 3) In the toolbox, double-click Project1.TestControl to add the modified ActiveX user control to the form.

Notice that the ActiveX user control in the Windows Form Designer and the references to AxProject1 and Project1 appear under References for UserControlDemo.
 * 1) On the Build menu, click Build Solution.

You do not receive any errors.

Note If you use this workaround, the modified ActiveX user control is added to your form as AxTestControl2, and your form still has some code that relates to AxTestControl1. For example, the following statement is still present, even though AxTestControl1 is no longer on your form:

Visual Basic .NET Sample Code Friend WithEvents AxTestControl1 As AxProject1.AxTestControl Visual C# .NET Sample Code private AxProject1.AxTestControl axTestControl1; If you used AxTestControl1 elsewhere in your code, and you did not explicitly create an instance of an AxProject1.AxTestControl object, you may receive a  error.

Moreover, if you have multiple forms with an instance of the ActiveX user control, you must repeat the previous steps for each form.

Method 2

 * 1) In Solution Explorer, under References, right-click AxProject1, and then click Remove.
 * 2) Under References, right-click Project1, and then click Remove.
 * 3) Open the Visual Studio .NET or Visual Studio 2005 command prompt, and then change the directory path to the bin directory of UserControlDemo.
 * 4) Type the following command, and then press the ENTER key to run Aximp.exe to explicitly generate a common language runtime proxy and a Windows Forms proxy:

aximp &quot;< >\Project1.ocx&quot; /out:AxInterop.Project1.dll

AxInterop.Project1.dll and Project1.dll are generated in the bin directory.

Note Replace  with the path of the directory that contains Project1.ocx.
 * 1) Switch to Visual Studio .NET or Visual Studio 2005. On the Project menu, click Add Reference.
 * 2) In the Add Reference dialog box that appears, click Browse.
 * 3) Locate AxInterop.Project1.dll and Project1.dll, and then select them.
 * 4) Click Open, and then click OK to add these references to your project.
 * 5) Close and reopen the Windows Form Designer.

Notice the modified ActiveX user control in the Windows Form Designer.

Note Unlike in the previous workaround, the modified ActiveX user control is still named AxTestControl1. Therefore, there is no unnecessary code.
 * 1) On the Build menu, click Build Solution.

You do not receive any errors.

Note These steps are based on the sample from the &quot;More Information&quot; section. Therefore, the entities mentioned in these tasks may differ from the entities in your project, depending on your implementation.



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
 Open Visual Basic 6.0, and then create an ActiveX Control project. In the Properties window, change   to TestControl .  On the View menu, click Code, and then add the following code: Public Sub Method1 MsgBox (&quot;Method 1&quot;) End Sub  On the File menu, click Make Project1.ocx, and then click OK in the Make Project dialog box that appears. Open Visual Studio .NET or Visual Studio 2005. Create a Windows application named UserControlDemo by using Visual Basic .NET, Visual Basic 2005, or Visual C# .NET. In Visual Studio .NET 2003, click Add/Remove Toolbox Items on the Tools menu.

In Visual Studio .NET 2002, click Customize Toolbox on the Tools menu.

In Visual Studio .2005, click Choose Toolbox Items on the Tools menu.</li> Click the COM Components tab, and then click Browse.</li> Locate Project1.ocx (created in Step 4), and then select it.</li> Click Open, and then click OK to add Project1.TestControl to the toolbox.</li> In the toolbox, double-click Project1.TestControl to add AxTestControl1 to the form.

The references to AxProject1 and Project1 automatically appear under References for UserControlDemo.</li> On the Build menu, click Build Solution.</li> Save the project, and then quit Visual Studio .NET or Visual Studio 2005.</li>  Switch to Visual Basic 6.0, and then add a public event, method, or property to TestControl. For example, append the following code to TestControl: Public Sub Method2 MsgBox (&quot;Method 2&quot;) End Sub </li> On the Project menu, click Project1 Properties.</li> In the Project1 - Project Properties dialog box that appears, click to select Component.</li> Under Version Compatibility, click to select Binary Compatibility, and then click OK.

Note Step 14 through step 16 describe how to select the Binary Compatibility option before recompiling the ActiveX user control.</li> On the File menu, click Make Project1.ocx.</li> Click Yes when you are prompted to replace the existing file.</li> Open Visual Studio .NET or Visual Studio 2005 and UserControlDemo.

Notice that TestControl1 is not visible in the Windows Form Designer.</li> On the Build menu, click Build Solution.

You receive the errors mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">