By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,660 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,660 IT Pros & Developers. It's quick & easy.

Getting 'Generic failure' error in ManagementClass.GetInstances()

P: 1
I am getting following error while iterating through the ManagementObjectCollection:
This error is coming only for the first time. From the 2nd run onwards the code is executed successfully. Surprisingly when I execute the code with the gap of 20-25 minutes the error is reproducible!

Please provide the solution urgently.

Thanks in Advance !

Please check the error details, sample C# code I am using.

Regards,

Sachin R.
================================================== ==
Expand|Select|Wrap|Line Numbers
  1. Error Details: 
  2.  
  3. ManagementException Error: Generic failure
  4. ManagementException Error code: Failed
  5. ManagementException ErrorInformation: System.Management.ManagementBaseObject
  6. ManagementException Error:    at System.Management.ManagementException.ThrowWith
  7. ExtendedInfo(ManagementStatus errorCode)
  8.    at System.Management.ManagementObjectEnumerator.MoveNext()
  9.    at TestWMI.Class2.Main(String[] args)
  10.  
================================================== ========
C# Code:
Description: Using following C# code: Problematic code line is marked in bold tag.

Expand|Select|Wrap|Line Numbers
  1.             try 
  2.             {
  3.                 string machineName = "dnsMachineName";
  4.                 System.Net.IPHostEntry iphe = System.Net.Dns.Resolve(machineName);
  5.                 string DnsServerName = iphe.HostName;
  6.                 string NameSpace = "\\\\" + DnsServerName + "\\root\\MicrosoftDNS";
  7.                 System.Management.ManagementScope EManagementScope = new System.Management.ManagementScope( NameSpace);
  8.                 EManagementScope.Connect();
  9.                 ManagementPath EZonePath = new ManagementPath("\\root\\MicrosoftDNS:MicrosoftDNS_Zone");
  10.                 ObjectGetOptions EGetOptions = new ObjectGetOptions();
  11.                 ManagementClass EManagementClass = new ManagementClass(EManagementScope , EZonePath, EGetOptions);
  12.                 ManagementObjectCollection mgmObjcoll =  EManagementClass.GetInstances();
  13.                 foreach (ManagementObject MyZoneObj in EManagementClass.GetInstances())                  {
  14.                     Console.WriteLine(MyZoneObj.Path);
  15.                     break;
  16.                 }
  17.             }
  18.             catch(ManagementException ex) 
  19.             {
  20.                 Console.WriteLine("ManagementException Error: "+ex.Message);
  21.                 Console.WriteLine("ManagementException Error code: "+ex.ErrorCode);
  22.                 Console.WriteLine("ManagementException ErrorInformation: "+ex.ErrorInformation);
  23.                 Console.WriteLine("ManagementException Error: "+ex.StackTrace);
  24.             }
Apr 2 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.