How should I gather Hardware Info if System.Management.dll
is not compatible with Dot Net Core.
How do I get the Machine info like Processor Id, Disk Volume number etc.
One of the things I did miss was a clear direction on how to reference a . NET dll directly (and of course still enjoy the benefits of intellisense), basically the same thing as doing Project > Add Reference > Browse in Visual Studio. And that's it!
Right click on the references in your project. Click Add Reference. Select the file (Project Root > Bin > System. Management.
dll from C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System. Management.
NET Core is supported on Mono (or if it even needs mono, now?), at least not entirely. Take a look here for what Mono supports. FastCGI is simply the server that runs ASP.NET code with mono. Now, having said that, is there a particular reason you need to run it on Linux?
.NET Core 3 now supports System.Management. As of this time, .NET Core 3 is in preview mode with preview 4 as the most current.
You will have to select the Manage NuGet packages... menu item under the Project menu in Visual Studio to install the latest version of System.Management
. Make sure that the include previews checkbox is selected so that you will install the latest version.
The previous version of System.Management
throws an error:
"Cannot marshal a string by-value with the [Out] attribute..."
See this link for more info about the error.
I am currently porting a Net Framework project that uses System.Management
to get some hardware info, and I also got to a dead end because System.Management
is not compatible with Net Core.
The workaround I found was to use Process.Start
from System.Diagnostics
to execute powershell commands to get that information, for instance, to get the motherboard serial number you can use the command Get-WmiObject Win32_BaseBoard | select SerialNumber
, you can then change the command to process the output and only have the serial number, or even process the output programatically.
You can also add some ifs
, that depending on the current OS you can provide to the Process.Start
specific OS commands, for instance, for linux you would need to process a dmidecode related command.
The only negative side in this approach is that its A LOT SLOWER whem compared with System.Management
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With