MatthewKing / DeviceId

A simple library providing functionality to generate a 'device ID' that can be used to uniquely identify a computer.
MIT License
785 stars 118 forks source link

Management Exception invalid class #81

Closed tbeattie63 closed 7 months ago

tbeattie63 commented 10 months ago

Using DeviceId 6.4.0, Device.Windows.Wmi 6.5.0

Possibly caused by locked down permissions on corporate network.

at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext() at System.Linq.Enumerable.d95`1.MoveNext() at DeviceId.Windows.Wmi.Components.WmiSystemDriveSerialNumberDeviceIdComponent.GetValue() at DeviceId.Formatters.HashDeviceIdFormatter.<>c.b4_1(KeyValuePair2 x) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at DeviceId.Formatters.HashDeviceIdFormatter.GetDeviceId(IDictionary2 components)

IsThatUniqueEnough commented 7 months ago

Exact same issue here. I think if getting the drive serial number (or any other id) can fail, the component should return null.

MatthewKing commented 7 months ago

Thank you both for the report. This will be fixed in the next release. This project doesn't currently have the resources to diagnose environment-specific permissions issues, so instead I'm just going to catch any exceptions here and have the component return null.

If you need the fix earlier than next release, you can just copy+paste the contents of the updated MmiSystemDriveSerialNumberDeviceIdComponent.cs file into your own project, give it a new name, and add it using the DeviceIdBuilder.AddComponent

IsThatUniqueEnough commented 7 months ago

Thanks. That's fine for me - my workaround was to wrap the existing component in an own one simply catching the exception.

In my case the problem happened on a standalone machine. Probably caused by a consumer security suite or a corrupted WMI. Wasn't able to investigate that further and the workaround did the job.