Microsoft KB Archive/307504

= BUG: Windows management instrumentation does not support all .NET data types =

Article ID: 307504

Article Last Modified on 3/4/2006

-

APPLIES TO


 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Windows Management Instrumentation in . NET

-



This article was previously published under Q307504



SYMPTOMS
When you use Windows Management Instrumentation (WMI) in Visual Studio 2005 or in Visual Studio .NET, you may receive a compile error on a valid .NET data type.



CAUSE
Some data types, such as Decimal, do not have an equivalent representation in WMI. If you want to expose properties of unsupported data types through instrumentation, you must supply your own conversion function that maps the unsupported data type to a supported instrumentation data type.



RESOLUTION
To work around this problem, expose the unsupported data type through instrumentation by using properties to cast to a supported data type. You can use this technique to expose members as an alternate data type, such as by exposing an Integer as a Double, or by exposing a DateTime as a String. The following example shows how you can expose a Decimal field on a class as a Double value through WMI. public class DecimalSample : Instance {       [IgnoreMember] public Decimal amount; [ManagedName(&quot;amount&quot;)] public double _amount {           get {               return (double)amount; }       }    }    class App {       static void Main {           DecimalSample instance = new DecimalSample; instance.amount = Decimal.Parse(&quot;7.310000&quot;); instance.Published = true; Console.WriteLine(&quot;Amount = {0}&quot;, instance.amount); Console.WriteLine(&quot;An instance of DecimalSample is now published to WMI.&quot;); Console.ReadLine; instance.Published = false; }   } You cannot expose the field Amount directly through instrumentation because Decimal is not a supported data type. The field Amount must have the IgnoreMember attribute. To expose an approximate value of the Amount field through WMI, define an _amount property that returns the value of Amount cast to a Double.

To make the WMI class appear as similar to the managed class as possible, use the ManagedName attribute to expose the _amount field as a WMI property named Amount. The end result is that you can access the Amount field of the DecimalSample class through managed code as a Decimal field, and WMI clients see a WMI property on the class Amount that contains the value cast to a Double.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.

Additional query words: kbreadme

Keywords: kbtshoot kbbug kbnofix kbreadme kbvs2002sp1sweep kbvs2005applies kbvs2005swept KB307504

-

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

© Microsoft Corporation. All rights reserved.