ManagementObjectCollection.Count bug/feature?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am attempting to do some development with WMI using C#. I have run into something that I'm not sure is a feature or a bug. When I run a query, or use the ManagementClass.GetInstances() method to return an ManagementObjectCollection that has no objects, the Count property causes a "Not Supported" exception to be thrown. I would have assumed that the value would be zero, but since it is not then I am forced to craft a not so elegant solution by catching this exception. This is obviously causing problems with foreach loops because the count value is coming from the ICollection.Count interface implementation

I've compared the documentation for the Framework v1.0 against the Framework v1.1 and found that in the earlier version it actually states that Count is not implemented, while the new version states that it is. However, I've found Count only to be implemented if the value is greater than zero

Could someone explain this to me, or at least verify my findings?
 
Back
Top