Microsoft KB Archive/834615

= You may receive a &quot;TargetInvocationException&quot; error message when you delete the UserControl1 user control from a Windows Service project in a Visual Basic .NET or Visual Basic 2005 application =

Article ID: 834615

Article Last Modified on 11/27/2007

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * 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.



Steps to reproduce the problem
 Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. 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. Add a Windows Control Library project that is named WindowsControlLibrary1 to the WindowsService1 solution. 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. 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. On the UserControl1.vb[Design] page, click the Toolbox, click the Components tab, and then click Microsoft FlexGrid Control, version 6.0.</li> On the Build menu, click Build Solution.

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

If you are using Visual Studio .NET 2002, follow these steps: <ol style="list-style-type: lower-alpha;"> Under Toolbox, click Components, right-click Components, and then click Customize Toolbox. The Customize Toolbox dialog box appears.</li> 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.</li> Click the WindowsControlLibrary1.dll file, and then click Open.</li> Click OK to close the Customize Toolbox dialog box.</li> 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 ---

</li> From the Components tab of the Toolbox, drag the UserControl1 user control to the Service1.vb[Design] page.</li></ol>

If you are using Visual Studio .NET 2003, click the My User Controls tab on the Toolbox, and then click UserControl1.</li> Try to delete the UserControl1 user control from the Service1.vb[Design] page.

You may receive the error message that is mentioned in the &quot;Symptoms&quot; section.</li></ol>

<div class="references_section">