I’m using the “Microsoft.Windows.Compatibility” package to get the baseboard serial number in a .NET 6 application. My code looks like this:
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
var mobos = searcher.Get();
foreach (var m in mobos)
{
return m["SerialNumber"].ToString() ?? "";
}
When I run this code in a console application, it works correctly. However, when I create a DLL that executes this code and load that DLL dynamically with LoadContext, I get the following error:
System.Management currently is only supported for Windows desktop applications.
How can I fix this problem?
Verified Package Installation: Ensured that the “Microsoft.Windows.Compatibility” package is installed and referenced in both the console application and the DLL project.
Target Framework: Confirmed that both the console application and the DLL project are targeting .NET
Mike Lopetgi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.