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



The information in this article 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 Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)
  • 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 "Symptoms" 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.
  4. 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 'NullReferenceException' 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 "<FilePath>\Project1.ocx" /out:AxInterop.Project1.dll

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

    Note Replace FilePath with the path of the directory that contains Project1.ocx.
  5. Switch to Visual Studio .NET or Visual Studio 2005. On the Project menu, click Add Reference.
  6. In the Add Reference dialog box that appears, click Browse.
  7. Locate AxInterop.Project1.dll and Project1.dll, and then select them.
  8. Click Open, and then click OK to add these references to your project.
  9. 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.
  10. On the Build menu, click Build Solution.

    You do not receive any errors.
Note These steps are based on the sample from the "More Information" 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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open Visual Basic 6.0, and then create an ActiveX Control project.
  2. In the Properties window, change Name to TestControl.
  3. On the View menu, click Code, and then add the following code:
    Public Sub Method1()
       MsgBox ("Method 1")
    End Sub
  4. On the File menu, click Make Project1.ocx, and then click OK in the Make Project dialog box that appears.
  5. 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.
  6. 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.
  7. Click the COM Components tab, and then click Browse.
  8. Locate Project1.ocx (created in Step 4), and then select it.
  9. Click Open, and then click OK to add Project1.TestControl to the toolbox.
  10. 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.
  11. On the Build menu, click Build Solution.
  12. Save the project, and then quit Visual Studio .NET or Visual Studio 2005.
  13. 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 ("Method 2")
    End Sub
  14. On the Project menu, click Project1 Properties.
  15. In the Project1 - Project Properties dialog box that appears, click to select Component.
  16. 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.
  17. On the File menu, click Make Project1.ocx.
  18. Click Yes when you are prompted to replace the existing file.
  19. Open Visual Studio .NET or Visual Studio 2005 and UserControlDemo.

    Notice that TestControl1 is not visible in the Windows Form Designer.
  20. On the Build menu, click Build Solution.

    You receive the errors mentioned in the "Symptoms" section of this article.

REFERENCES

For additional information, click the following article number to view the article in the Microsoft Knowledge Base: For more information, visit the following MSDN Web Sites:

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbIDEProject kbide kbComCtrls kbCtrlCreate kbCtrl kbControl kbCOMInterop kbprb KB818220 kbAudDeveloper