How to use System.Management ManagementObjectSearcher in .net 6

Robert Crockett 21 Reputation points
2022-01-26T20:09:35.417+00:00

We are upgrading to .Net 6. This code worked fine in .Net 5:

        public static string GetSystemUUID()
        {
            string uuid = "";
            ManagementObjectSearcher Searcher = new ManagementObjectSearcher("SELECT UUID FROM Win32_ComputerSystemProduct");

            foreach (ManagementObject WmiObject in Searcher.Get())
            {
                uuid = WmiObject["UUID"].ToString();
            }

            return uuid;
        }

I have upgraded to System.Management to 6.0.0 and upgraded all microsoft extension pacakges and aspnet core packages to .Net 6. I still get the following Exception:

"The type initializer for 'System.Management.ManagementPath' threw an exception."

With this inner exception:

"Built-in COM has been disabled via a feature switch. See https://aka.ms/dotnet-illink/com for more information."

Windows 10 Compatibility
Windows 10 Compatibility
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Compatibility: The extent to which hardware or software adheres to an accepted standard.
456 questions
{count} votes