I'm trying to get this simple piece of code to work.
public void GetHDDSerial()
{
var hdd = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE Index = '0'")
.Get()
.Cast<ManagementObject>()
.First();
MessageBox.Show(hdd["Model"].ToString());
}
using System.Management
is present, and I've also made a reference to the assembly (Visual Studio > Project > Add Reference > System.Management).
The error I'm getting is that the Get() method is not defined. Specifically:
Error CS1061 'ManagementObjectSearcher' does not contain a definition for 'Get' and no extension method 'Get' accepting a first argument of type 'ManagementObjectSearcher' could be found (are you missing a using directive or an assembly reference?)
How come? I thought that the getters and setters were predefined. Do I need to reference anything else?
EDIT: Going through the ManagementObjectSearcher, and listing all the methods that are actually there, I get these methods: ToString
, Equals
, GetHashCode
, GetType
.
EDIT #2: Going to the definition (F12, or right-clicking), I get this:
namespace myProgram
{
internal class ManagementObjectSearcher
{
private string v;
public ManagementObjectSearcher(string v)
{
this.v = v;
}
}
}
.NET version is 4.6.01055, and I'm using Visual Studio 2015 Enterprise.