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("amount")] public double _amount
{
get
{
return (double)amount;
}
}
}
class App
{
static void Main()
{
DecimalSample instance = new DecimalSample();
instance.amount = Decimal.Parse("7.310000");
instance.Published = true;
Console.WriteLine("Amount = {0}", instance.amount);
Console.WriteLine("An instance of DecimalSample is now published to WMI.");
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.