ManagementObjectCollection.Count bug/feature?

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top