MatthewKing / DeviceId

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

NET8.0 DeviceId.Windows.Mmi not working #76

Open xevilmaxx opened 1 year ago

xevilmaxx commented 1 year ago

Hi, Recently i was migrating one of my projects to NET8 RC2. Noted that DeviceId.Windows.Mmi throws an error.

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at DeviceId.Windows.Mmi.Components.MmiWqlDeviceIdComponent.GetValue()

the package which throws the error is included inside DeviceId.Windows.Mmi

by removing MMI reference, at least for windows (11) all seems to work.

The error occurs only on runtime, but compiles fine. Inside build folder there are files like: *DeviceId..dll but no explicitly the dll that throws the error althought i assume its included in DeviceId.Windows.Mmi.dll**

here is my configuration:


//excluding wireless and non physical becouse they might change MAC more easily
var deviceIdBuilder = new DeviceIdBuilder()
    .AddOsVersion()
    .OnWindows(windows => windows
        .AddMachineGuid()
        .AddWindowsDeviceId()
        .AddWindowsProductId()
        //mmi stopped working in NET8.0
        //.AddMacAddressFromMmi(excludeWireless: true, excludeNonPhysical: true)
        //.AddSystemUuid()
        )
    .OnLinux(linux => linux
        .AddProductUuid()
        .AddMotherboardSerialNumber()
        )
    .OnMac(mac => mac
        .AddPlatformSerialNumber()
        );

//Processor Id creates issues on linux as it may change (if programm is executing on different Processor from before)
//[Windows] -> AddSystemUuid seems not to be unique (at least in .NET)
var MachineId = deviceIdBuilder
    .UseFormatter(new HashDeviceIdFormatter(() =>
        SHA256.Create(),
        new Base64UrlByteArrayEncoder()
     ))
    .ToString();

Thanks in advance.

MatthewKing commented 1 year ago

There are some pitfalls with MMI.

Please see the following: https://github.com/MatthewKing/DeviceId/issues/36#issuecomment-901846204

MatthewKing commented 1 year ago

Hi, did you end up resolving this or are you still having issues?

xevilmaxx commented 1 year ago

Simply removed MMI dependency and used only core options

On Tue, Nov 7, 2023, 04:52 Matthew King @.***> wrote:

Hi, did you end up resolving this or are you still having issues?

— Reply to this email directly, view it on GitHub https://github.com/MatthewKing/DeviceId/issues/76#issuecomment-1797702711, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEGVOYRAAZFQHGA6UWQLHWTYDGWBTAVCNFSM6AAAAAA6FDOLWOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJXG4YDENZRGE . You are receiving this because you authored the thread.Message ID: @.***>