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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sachinrohamare
    New Member
    • Apr 2007
    • 1

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

    I am getting following error while iterating through the ManagementObjec tCollection:
    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.
    =============== =============== =============== =======
    Code:
    Error Details: 
    
    ManagementException Error: Generic failure
    ManagementException Error code: Failed
    ManagementException ErrorInformation: System.Management.ManagementBaseObject
    ManagementException Error:    at System.Management.ManagementException.ThrowWith
    ExtendedInfo(ManagementStatus errorCode)
       at System.Management.ManagementObjectEnumerator.MoveNext()
       at TestWMI.Class2.Main(String[] args)
    =============== =============== =============== =============
    C# Code:
    Description: Using following C# code: Problematic code line is marked in bold tag.

    Code:
    			try 
    			{
    				string machineName = "dnsMachineName";
    				System.Net.IPHostEntry iphe = System.Net.Dns.Resolve(machineName);
    				string DnsServerName = iphe.HostName;
    				string NameSpace = "\\\\" + DnsServerName + "\\root\\MicrosoftDNS";
    				System.Management.ManagementScope EManagementScope = new System.Management.ManagementScope( NameSpace);
    				EManagementScope.Connect();
    				ManagementPath EZonePath = new ManagementPath("\\root\\MicrosoftDNS:MicrosoftDNS_Zone");
    				ObjectGetOptions EGetOptions = new ObjectGetOptions();
    				ManagementClass EManagementClass = new ManagementClass(EManagementScope , EZonePath, EGetOptions);
    				ManagementObjectCollection mgmObjcoll =  EManagementClass.GetInstances();
    				[B]foreach (ManagementObject MyZoneObj in EManagementClass.GetInstances()) [/B] 				{
    					Console.WriteLine(MyZoneObj.Path);
    					break;
    				}
    			}
    			catch(ManagementException ex) 
    			{
    				Console.WriteLine("ManagementException Error: "+ex.Message);
    				Console.WriteLine("ManagementException Error code: "+ex.ErrorCode);
    				Console.WriteLine("ManagementException ErrorInformation: "+ex.ErrorInformation);
    				Console.WriteLine("ManagementException Error: "+ex.StackTrace);
    			}
    Last edited by kenobewan; Apr 2 '07, 12:54 PM. Reason: Add code tags
Working...