You may receive a "TargetInvocationException" error message when you delete the UserControl1 user control from a Windows Service project in a Visual Basic .NET or Visual Basic 2005 application (834615)



The information in this article applies to:

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

SYMPTOMS

When you try to delete the UserControl1 user control from Component Designer in a Windows Service project, and the UserControl1 user control contains a Windowless ActiveX control, you may receive the following error message:
The following exception has occurred:
TargetInvocationException: Unable to get the window handle for the 'AxMSFlexGrid' control. Windowless ActiveX controls are not supported.

CAUSE

The UserControl1 user control that contains the Windowless ActiveX controls is not currently supported in a Windows Service project.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to reproduce the problem

  1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. Create a new Microsoft Visual Basic .NET or Microsoft Viusal Basic 2005 Windows Service project that is named WindowsService1. By default, the project is created under the solution that is named WindowsService1.
  3. Add a Windows Control Library project that is named WindowsControlLibrary1 to the WindowsService1 solution.
  4. Open the Customize Toolbox dialog box.

    To do this in Visual Studio .NET 2002, right-click Components under Toolbox, and then click Customize Toolbox.

    To do this in Visual Studio .NET 2003, right-click Components under Toolbox, and then click Add/Remove Items.

    To do this in Visual Studio 2005, right-click Components under Toolbox, and then click Choose Items.
  5. In the Customize Toolbox dialog box, click to select the Microsoft FlexGrid Control, version 6.0 check box on the COM Components tab, and then click OK.
  6. On the UserControl1.vb[Design] page, click the Toolbox, click the Components tab, and then click Microsoft FlexGrid Control, version 6.0.
  7. On the Build menu, click Build Solution.

    The Windowscontrollibrary1.dll file is created.
  8. In Solution Explorer, double-click the Service1.vb file under the WindowsService1 project.
  9. Add the UserControl1 user control to the Service1.vb[Design] page.

    If you are using Visual Studio .NET 2002, follow these steps:
    1. Under Toolbox, click Components, right-click Components, and then click Customize Toolbox. The Customize Toolbox dialog box appears.
    2. In the Customize Toolbox dialog box, click the .NET Framework Components tab, and then click Browse to locate the WindowsControlLibrary1.dll file that you created in step 7.
    3. Click the WindowsControlLibrary1.dll file, and then click Open.
    4. Click OK to close the Customize Toolbox dialog box.
    5. From the Components tab of the Toolbox, drag the UserControl1 user control to the Service1.vb[Design] page.

      Note If you receive the following error message, click OK to close the error message dialog box:
      --------------------------- Microsoft Development Environment --------------------------- The .NET assembly 'Interop.MSFlexGridLib' could not be found. --------------------------- OK ---------------------------
    6. From the Components tab of the Toolbox, drag the UserControl1 user control to the Service1.vb[Design] page.
    If you are using Visual Studio .NET 2003, click the My User Controls tab on the Toolbox, and then click UserControl1.
  10. Try to delete the UserControl1 user control from the Service1.vb[Design] page.

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

REFERENCES

For additional information, visit the following Microsoft Developer Network (MSDN) Web sites:

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbToolbar kbService kbMsg kbDLL kbControl kbUser kbprb KB834615 kbAudDeveloper