- Home /
The type or namespace name "Management" does not exist in the namespace
I am using "WMI C#" To try to display my computer Processor information onto a UI in unity. But I can not figure out why this will not work, I have tried adding System.Management as a reference as well that did not work, I also tried using "PerformanceCounter" but could not get that to work at all as well, Maybe the code does not work for unity, no clue still learning code so maybe I am over looking something so I figured I would ask on here and maybe someone can point me in the right direction with this project
thanks in advance. here is the code I am currently trying to get to work.
using UnityEngine;
using System;
using System.Management;
namespace SystemInformation
{
public class USAGE
{
static void Main(string[] args)
{
GetComponent("Win32_Processor", "LoadPercentage");
}
private static void GetComponent(string hwclass, string syntax)
{
ManagementObjectSearcher mos = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM " + hwclass);
foreach (ManagementObject mj in mos.Get())
{
UnityEngine.Debug.Log(Convert.ToString(mj[syntax]));
}
}
}
}
That library isn't standard on .NET. You'll need to add it to your project:
https://stackoverflow.com/questions/4193883/where-are-my-system-management-classes
I deleted my previous comment because I figured out what you meant. But I already had System.$$anonymous$$anagement added as a reference in the project I'm guessing that its not working with unity because it shows no error on visual studio but when I tab into unity it shows the error in the image I linked. any other ideas?
Answer by SepraB · Jul 10, 2018 at 03:32 PM
@braydon97 What you need to do is:
Go into your **C\: Program Files\Unity installation folder\Editor\Data\Mono\lib\mono\2.0**
Copy the file named "System.Management.dll"
Go into your Project directory and in the Assets folder create a folder named "Plugins"
Paste the DLL into the Plugins folder.
Wait for Unity to compile the scripts and use the reference as normally.
It worked for me on Windows. Hope it works for you.
I did it based on this topic/answer: How to solve the error: "type or namespace system.data does not exist" in $$anonymous$$ac OS X - @kittikunJP answer
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
how can i use spot light in canvas 2d 0 Answers
How do you duplicate/reuse scripts that have references to other scripts. 1 Answer