C# Erreur - espaces de noms ManagementClass, ManagementObject, et ManagementObjectCollection n'a pas pu être trouvé
Donc, j'ai une liste complète des erreurs après l'importation d'une Classe C#. J'ai cherché l'erreur, et vous avez une tonne de coups mais ils ont tous dis il suffit d'ajouter le Système.La gestion de l'espace de noms qui est là et pourtant, il donne à ces erreurs.
Des questions similaires. Aucune solution n'a fonctionné pour moi:
Manquant directive ou une référence d'assembly à l'aide de WMI ManagementObjectSearcher?
'ManagementClass" n'existe pas dans l'espace de noms du Système".De " gestion de
Classe:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Net;
using System.Xml;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Threading;
using System.Management;
using Microsoft.Win32;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
namespace PCID_Grabber
{
public class PCID
{
public static string GetCPUId()
{
#region CPUid
string cpuInfo = String.Empty;
string temp = String.Empty;
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == String.Empty)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
}
return cpuInfo;
#endregion
}
public static string GetMotherBoardID()
{
#region Mboard
ManagementObjectCollection mbCol = new ManagementClass("Win32_BaseBoard").GetInstances();
ManagementObjectCollection.ManagementObjectEnumerator mbEnum = mbCol.GetEnumerator();
mbEnum.MoveNext();
return ((ManagementObject)(mbEnum.Current)).Properties["SerialNumber"].Value.ToString();
#endregion
}
public static string GetMacAddress()
{
#region MacAddress
string macs = "";
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in interfaces)
{
PhysicalAddress pa = ni.GetPhysicalAddress();
macs += pa.ToString();
}
return macs;
#endregion
}
public static string GetVolumeSerial()
{
#region HD serial
string strDriveLetter = "";
ManagementClass mc = new ManagementClass("Win32_PhysicalMedia");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
try
{
if ((UInt16)mo["MediaType"] == 29)
{
String serial = mo["SerialNumber"].ToString().Trim();
if (!String.IsNullOrEmpty(serial))
{
strDriveLetter = (string)mo["SerialNumber"];
return strDriveLetter;
}
}
}
catch { }
}
return strDriveLetter;
#endregion
}
public static string GetGenericID()
{
#region UID
string ID = GetCPUId() + GetMotherBoardID() + GetMacAddress() + GetVolumeSerial();
HMACSHA1 hmac = new HMACSHA1();
hmac.Key = Encoding.ASCII.GetBytes(GetMotherBoardID());
hmac.ComputeHash(Encoding.ASCII.GetBytes(ID));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hmac.Hash.Length; i++)
{
sb.Append(hmac.Hash[i].ToString("X2"));
}
return sb.ToString();
#endregion
}
}
}
Liste des Erreurs:
Error 1 The type or namespace name 'ManagementClass' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Keanu\workspace\PCID Grabber\PCID Grabber\pcid.cs 31 13 PCID Grabber
Error 2 The type or namespace name 'ManagementClass' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Keanu\workspace\PCID Grabber\PCID Grabber\pcid.cs 31 38 PCID Grabber
Error 5 The type or namespace name 'ManagementClass' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Keanu\workspace\PCID Grabber\PCID Grabber\pcid.cs 46 52 PCID Grabber
Error 8 The type or namespace name 'ManagementClass' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Keanu\workspace\PCID Grabber\PCID Grabber\pcid.cs 69 13 PCID Grabber
Error 9 The type or namespace name 'ManagementClass' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Keanu\workspace\PCID Grabber\PCID Grabber\pcid.cs 69 38 PCID Grabber
Error 7 The type or namespace name 'ManagementObject' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Keanu\workspace\PCID Grabber\PCID Grabber\pcid.cs 49 22 PCID Grabber
Error 3 The type or namespace name 'ManagementObjectCollection' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Keanu\workspace\PCID Grabber\PCID Grabber\pcid.cs 32 13 PCID Grabber
Error 4 The type or namespace name 'ManagementObjectCollection' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Keanu\workspace\PCID Grabber\PCID Grabber\pcid.cs 46 13 PCID Grabber
Error 6 The type or namespace name 'ManagementObjectCollection' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Keanu\workspace\PCID Grabber\PCID Grabber\pcid.cs 47 13 PCID Grabber
Error 10 The type or namespace name 'ManagementObjectCollection' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Keanu\workspace\PCID Grabber\PCID Grabber\pcid.cs 70 13 PCID Grabber
OriginalL'auteur user3851422 | 2014-07-18
Vous devez vous connecter pour publier un commentaire.
Vous devez également ajouter une référence d'assembly à votre projet. Vous avez besoin de faire référence à la
System.Management
assemblage de votre projet, sinon leusing
déclarations ne seront pas en mesure de localiser les espaces de nomsOriginalL'auteur Leo