Microsoft KB Archive/309334

= BUG: Generated Code Does Not Compile When a Management Strongly Typed Class Has a Method That Uses a Void Return Type =

Article ID: 309334

Article Last Modified on 7/17/2002

-

APPLIES TO


 * Microsoft Windows Management Instrumentation in . NET

-



This article was previously published under Q309334



SYMPTOMS
When you generate a management strongly typed class for a Windows Management Instrumentation (WMI) class that has a method that uses a void return type, the generated code does not compile.

This behavior occurs when you generate a management strongly typed class by using the Management Strongly Typed Class Generator tool (Mgmtclassgen.exe) or by using WMI Extensions in Server Explorer.



CAUSE
The code that is generated by the tool calls ManagementObject.InvokeMethod, which takes three parameters. In situations when the WMI class method returns void, the generated code calls InvokeMethod with the first two parameters, but the third parameter (the InvokeMethodOptions object) is missing.



RESOLUTION
This behavior can occur in three different scenarios. The following are workarounds for each scenario.

Scenario
You use code that is generated by using the Management Strongly Typed Generator (MgmtClassGen.exe) to generate a managed class for a WMI class.

Workaround
Manually add null as the third parameter of ManagementObject.InvokeMethod.

Scenario
You use code that is generated by using Server Explorer to generate a managed class for a WMI class.

Workaround
Manually add null as the third parameter of ManagementObject.InvokeMethod.

Scenario
You drag an instance of the class from Server Explorer to a Windows Form or to a Web Form Application.

Workaround
Manually add the null parameter for ManagementObject.InvodeMethod. Additionally, you must add a member variable for the class, and then add initialization code to the application to replace the code that would have been generated by the drag-and-drop process. Add the following sample code. (In these samples, the class generated is named MyClass, and it is located in the ROOT\DEFAULT namespace.)

For a Windows Form Application, add the following sample code:

In Visual C# .NET
// Add a member variable to the application class.

private WindowsApplication1.ROOT.DEFAULT.MyClass MyClass1;

// Initalization code to be added to InitializeComponent: this.MyClass1 = new WindowsApplication1.ROOT.DEFAULT.MyClass;

// Complete WMI path of the instance that you dragged: this.MyClass1.Path = new System.Management.ManagementPath(&quot;root\\DEFAULT:MyClass.Id=10&quot;);

In Visual Basic .NET
' Add a member variable to the application class. Friend WithEvents MyClass1 As WindowsApplication1.ROOT.DEFAULT.MyClass

' Initialization Code to be added to InitializeComponent: Me.MyClass1 = New WindowsApplication1.ROOT.DEFAULT.MyClass

' Complete WMI path of the instance that you dragged: Me.MyClass1.Path = _ New System.Management.ManagementPath(&quot;root\DEFAULT:MYClass.Id=10&quot;)



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

Additional query words: kbreadme

Keywords: kbbug kbreadme kbpending KB309334

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.