Я пытаюсь найти, что моя машина является хранилищем iscsi, но ниже функция выдаёт ошибку Generi c:
StackTrace = " at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus
errorCode)\r\n at system.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()\r\n at System.Management.ManagementObjectCollection.get_Count()\r\n
Мой код:
private string GetISCSInfo(string DeviceID)
{
string StorageType = "Local";
try
{
var scope = new ManagementScope("\\\\.\\ROOT\\WMI");
**SelectQuery query = new SelectQuery("SELECT * FROM MSISCSIInitiator_TargetClass");**
ManagementObjectSearcher iscsiSearcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection iscsiCollection;
string iscsiDeviceID = null;
***//Get() is calling using validSearch function in this function error is throwing***
if (validSearch(iscsiSearcher, out iscsiCollection))
{
foreach (ManagementObject item in iscsiCollection)
{
if (validField(item, "InitiatorName"))
{
iscsiDeviceID = item["InitiatorName"].ToString();
if (string.Equals(iscsiDeviceID, DeviceID, StringComparison.OrdinalIgnoreCase))
{
StorageType = "iSCSI";
}
}
}
}
}
catch (Exception)
{
throw;
}
return StorageType;
}
//Error getting while count is checking
public bool validSearch(ManagementObjectSearcher searcher,
out ManagementObjectCollection collection)
{
collection = searcher.Get();
bool result = false;
try
{
if (collection.Count > 0)
{
result = true;
}
}
catch (Exception e)
{
Trace.TraceWarning("Exception caught while running query: " + e);
//Invalid
}
return result;
}