Search code examples
c#.net.net-core.net-5system.management

How to fix "System.Management is supported on Windows Desktop Apps only" Exception


The Issue:

Our application is a .NET 5 Windows Desktop application. The licensing capability requires the application to use the System.Management component from NuGet to create a unique device ID from the system processor ID, MAC Address and BIOS serial number.

This all worked great when testing it from Visual Studio debugger. However, when adding System.Management.dll to the application installer (InstallShield installer) I naturally selected the version of System.Management.dll that was in the app's build target folder. It turns out that the version of the DLL that ends up in that folder is a no-op version that throws not supported exceptions saying "System.Management is supported on Windows Desktop Apps only".


Solution

  • I think perhaps this is because the deps.json file is missing, causing the stub version to be loaded from the application directory, rather than the one from the runtimes directory. So either the desired dependency could be installed to the application root directory, or the existing hierarchy from the build directory could be maintained, but also distributing the dependency configuration.

    https://learn.microsoft.com/en-us/dotnet/core/dependency-loading/default-probing