Hi,
Here are sections of my codes:
private void test()
{
ObjectQuery objectQuery = new ObjectQuery("se lect * from
Win32_NetworkAd apterConfigurat ion");
ManagementObjec tSearcher searcher = new
ManagementObjec tSearcher(objec tQuery);
foreach (ManagementObje ct share in searcher.Get())
{
AppendObject(sh are);
}
}
private void AppendObject(Ma nagementObject obj)
{
PropertyDataCol lection dataCollection = obj.Properties;
foreach (PropertyData data in dataCollection)
{
if (data.IsArray)
{
object[] tempArray = (object[])(obj[data.Name]);
if (tempArray != null)
{
AppendString(te xtBox1, data.Name);
foreach (object temp in tempArray)
{
if (temp != null)
Debug.WriteLine (temp.ToString( ));
}
}
}
else
{
object temp = obj[data.Name];
if (temp != null)
{
AppendString(te xtBox1, data.Name + " = " + temp.ToString() );
}
else
AppendString(te xtBox1, data.Name);
}
}
AppendString(te xtBox1, "");
}
My question is why do I got an "System.Invalid CastException" when the code
reaches the line:
object[] tempArray = (object[])(obj[data.Name]);
when data.Name is GatewayCostMetr ic.
According to platform SDK, GatewayCostMetr ic is an array of uint16 and the
in fact the Type property for the data.Type is CimType.UInt16.
I have trace through and be able to cast array of strings to array of
objects. Why is this cast invalid?
Any one can help me on this? Thanks.
Here are sections of my codes:
private void test()
{
ObjectQuery objectQuery = new ObjectQuery("se lect * from
Win32_NetworkAd apterConfigurat ion");
ManagementObjec tSearcher searcher = new
ManagementObjec tSearcher(objec tQuery);
foreach (ManagementObje ct share in searcher.Get())
{
AppendObject(sh are);
}
}
private void AppendObject(Ma nagementObject obj)
{
PropertyDataCol lection dataCollection = obj.Properties;
foreach (PropertyData data in dataCollection)
{
if (data.IsArray)
{
object[] tempArray = (object[])(obj[data.Name]);
if (tempArray != null)
{
AppendString(te xtBox1, data.Name);
foreach (object temp in tempArray)
{
if (temp != null)
Debug.WriteLine (temp.ToString( ));
}
}
}
else
{
object temp = obj[data.Name];
if (temp != null)
{
AppendString(te xtBox1, data.Name + " = " + temp.ToString() );
}
else
AppendString(te xtBox1, data.Name);
}
}
AppendString(te xtBox1, "");
}
My question is why do I got an "System.Invalid CastException" when the code
reaches the line:
object[] tempArray = (object[])(obj[data.Name]);
when data.Name is GatewayCostMetr ic.
According to platform SDK, GatewayCostMetr ic is an array of uint16 and the
in fact the Type property for the data.Type is CimType.UInt16.
I have trace through and be able to cast array of strings to array of
objects. Why is this cast invalid?
Any one can help me on this? Thanks.
Comment