Hello,
Im using WMI to get CPU information through Win32_Processor.
It returns a collection but some items are "not valid".
....
foreach( ManagementObject oReturn in oReturnCollection )
{
Console.WriteLine(oReturn["Manufacturer"].ToString());
Console.WriteLine(oReturn["ProcessorId"].ToString());
}
If oReturn["ProcessorId"] does not "exist" it crash with error:
Additional information: Object reference not set to an instance of an object.
How can I test to see if oReturn["ProcessorId"] is set to an instance
befor I WriteLine(...) it?
Thanks,
Joao Rego
Salvador - 22 Dec 2005 14:28 GMT
Hi,
I had the same problem, use
if (oReturn["ProcessorId"] != null)
<read operations here>
Cheers

Signature
Salvador Alvarez Patuel
Exony Ltd - London, UK
> Hello,
>
[quoted text clipped - 17 lines]
>
> Joao Rego
Joao Rego - 22 Dec 2005 14:36 GMT
OK... that's it... thanks for your help.
> Hi,
>
[quoted text clipped - 26 lines]
> >
> > Joao Rego
Stoitcho Goutsev (100) [C# MVP] - 22 Dec 2005 14:30 GMT
Joao,
what if you first read the property in a object variable and check this
variable for *null* before printing it out?

Signature
Stoitcho Goutsev (100) [C# MVP]
> Hello,
>
[quoted text clipped - 18 lines]
>
> Joao Rego