Closed profix898 closed 3 years ago
Thanks for filing this issue and providing the info. I've been super busy with life recently so I haven't had the time to give DeviceId as much love as it deserves - particularly when chasing the moving target that is netcore/net5.0/crossplat/etc.
I've pushed some code which I believe will address this issue. It'll remove the dependency on the PlatformAbstractions package, and replace WMI with MMI.
Would you mind having a look and letting me know if this would solve your issue?
Thanks
I've been super busy with life recently
I know the feeling ... still DeviceId is a pretty useful library :)
Your latest changes are looking good. I built the project and used it in a net5.0 console app. It seems the net5.0 issue got resolved. Thanks a lot!
Please allow me to include some comments for a follow up:
RegistryValueDeviceIdComponent.cs(46,29): warning CA1416: This call site is reachable on all platforms. 'Registry.GetValue(string, string?, object?)' is only supported on: 'windows'. [.\DeviceId\src\DeviceId\DeviceId.csproj]
I guess it would be good to wrap that call with 'RuntimeInformation.IsOSPlatform(OSPlatform.Windows)' and return String.Empty (or something) on other platforms.Regards
Thanks for the review, I really appreciate it.
I'll be releasing v5.3.0 later today. Thanks again for the feedback and assistance.
Unfortunately when using this on .NET 5.0, I am running into the following issue:
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.Internal.Wmi.GetSystemDriveSerialNumber()
at DeviceId.Components.SystemDriveSerialNumberDeviceIdComponent.GetValue()
at DeviceId.Formatters.HashDeviceIdFormatter.<>c.<GetDeviceId>b__3_1(IDeviceIdComponent x)
at System.Linq.Enumerable.SelectIPartitionIterator`2.PreallocatingToArray(Int32 count)
at System.Linq.Enumerable.SelectIPartitionIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at DeviceId.Formatters.HashDeviceIdFormatter.GetDeviceId(IEnumerable`1 components)
at DeviceId.DeviceIdBuilder.ToString()
After publishing
Hi Daniel.
I can't reproduce this issue on my PC - everything seems to work fine with .NET 5 on v5.3.0 of DeviceId.
Are you able to put together a small example project that demonstrates that issue?
What platform/runtime are you using? You don't have a build script that is removing the runtimes directory do you?
Cheers
@DanielMcAssey: Looks like the MMI 2.0 package has different native/runtime dependencies for each Windows version (see https://www.nuget.org/packages/Microsoft.Management.Infrastructure.Runtime.Win/2.0.0). So instead of 'win-x64' as your target runtime for publishing, you need to be more specific, such as 'win10-x64' (or 'win8-x64'). Then the correct version will be included when publishing the project. Not sure that's on purpose or simply an oversight on MS's part.
Hi there, Here you go: https://github.com/DanielMcAssey/device-id-repro If you debug it works fine, if you do a self-contained publish it breaks, I have an example broken self-contained publish.
EDIT: A @profix898 I will give that a go. The only issue is, I think we would need to distribute multiple versions of the same app
For reference: https://github.com/PowerShell/MMI/issues/45
Thanks Daniel. Not sure what to do about this one (at least until https://github.com/PowerShell/MMI/issues/45 is resolved)...
DeviceId targets .NETStandard 2.0, so in principle it should work on net5.0. Unfortunately, the project uses the obsolete platform abstraction package, which is not available for net5.0 (except for an old preview version). For that reason, it would be great to have a net5.0 target. Once #25 is merged, the net5.0 version would be identical to the netStandard version, except for the deprecated dependency.
See https://docs.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/5.0/platformabstractions-package-removed for details.