4

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.

3
  • Does this answer your question? Could not load file or assembly or one of its dependencies Commented Dec 1, 2023 at 5:42
  • @JoshuaFrank sorry no, but I will have to revisit it at some point. Commented Jan 9, 2024 at 19:27
  • Have you published first? Commented Jan 12, 2024 at 0:01

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Had the same issue deploying a .Net 6.0 app. Including the runtimes folder solved it for me, many thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.