Could not load file or assembly 'System.Management, Version=8.0.0.0, Culture-neutral, etc.'

334 views Asked by At

I have a .NET Core 6 WPF application using System.Management namespace to query connected devices on my windows computer like so:

string query = "SELECT * FROM Win32_PnPEntity WHERE (PNPClass = 'Image' OR PNPClass = 'Camera')";
using ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

The code works fine in debug mode. However, when I build the msi file (using Advanced Installer), the program throws an exception when the application hits this same code. The exception raised is:

Could not load file or assembly 'System.Management, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

This is odd to me because when I look into where the files are deposited in the application folder, all the necessary dll's are there.

What is even weirder is that I can run the application with no problem if I run it from the bin folder (that is, I double click on the executable from that location). I even have copied and pasted that bin folder to other locations on my computer (such as the C drive) to see if there is any issues with my permissions as a user. Perhaps that is the issue why it can't detect the file. Yet, the application runs fine this way, it is only when I deploy it from the msi file created by Advanced Installer that I get this error.

If anyone can help that would be greatly appreciated.

1

There are 1 answers

0
Joshua Frank On

Not sure if this is the same issue as the OP, but I had this issue when deploying a .NET 8 application without the needed runtimes folder generated by the build. When I updated my setup program to install this runtimes folder to the output folder on the destination machine, it fixed this problem.