MatthewKing / DeviceId

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

System.PlatformNotSupportedException on Win Server 2012 #29

Closed jarenduan closed 2 years ago

jarenduan commented 3 years ago

Hi, I write a .net5 app that try to get the machine id. The code is simple:

public string GetId() => new DeviceIdBuilder()
                                 .AddProcessorId()
                                 .AddMacAddress(true, true)
                                 .ToString();

It works fine on win 10, but on a win server 2012 I get this error: System.PlatformNotSupportedException: The native library 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\wminet_utils.dll' does not have all required functions. Please, update the .NET Framework.

I then install the .net framework 4.8 , but it doesn't help.

MatthewKing commented 2 years ago

I'm not really familiar with Server 2012 but it looks like it is missing some of the required WMI bits.

You could try targeting .NET Core / .NET 5.

Or you could try the MMI functionality in the v6 alpha release:

var deviceId = new DeviceIdBuilder()
    .OnWindows(windows => windows.AddProcessorId().AddMacAddressFromMmi(true, true))
    .ToString();