Microsoft.Win32.Registry无法在.net标准2.0库中运行 [英] Microsoft.Win32.Registry not working in .net standard 2.0 library
问题描述
大家好我正在尝试构建一个.net标准2.0库,它从注册表中获取机器ID,它给了我这个错误
InnerException {System.IO.FileLoadException:无法加载文件或程序集'Microsoft.Win32.Registry,Version = 4.1.0.0,Culture = neutral ,PublicKeyToken = b03f5f7f11d50a3a'。定位程序集的清单定义确实
与程序集引用不匹配。 (HRESULT异常:0x80131040)
文件名:'Microsoft.Win32.Registry,Version = 4.1.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'
at SteamKit2.WindowsInfoProvider.GetMachineGuid()
at SteamKit2.HardwareUtils.GenerateMachineID()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
} System.Exception {System.IO.FileLoadException}
避免直接使用注册表;在可用时使用文档解决方案我不确定你所说的"机器ID"是什么意思但请查看WMI,如
System.Managenet命名空间;
ManagementClass Class 及相关类。
Hello guys i am trying to build a .net standard 2.0 library that get machine id from the registry and it gives me this error
InnerException {System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Win32.Registry, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does
not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Microsoft.Win32.Registry, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at SteamKit2.WindowsInfoProvider.GetMachineGuid()
at SteamKit2.HardwareUtils.GenerateMachineID()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
} System.Exception {System.IO.FileLoadException}
Avoid using the registry directly; use documented solutions when available. I am not sure what you mean by "machine id" but look at WMI as in the System.Managenet namespace; the ManagementClass Class and related classes.
这篇关于Microsoft.Win32.Registry无法在.net标准2.0库中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!