How to handle: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

kaygroth2
kaygroth2 used Ask the Experts™
on
I'm working on a little utility in c# to grab data from a bunch of computers on a domain via WMI, i already have a section which find out if the machine is reachable and if it is then it uses WMI to gather the information from the machine.

However,sometimes i'm getting the below exception and im wondering how i should be handling it. The section where the WMI info is retrieved is already in a try catch block, but i want to be able to keep going if this exception occurs.

below is the exception in question:

Unhandled Exception: System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Management.ManagementScope.InitializeGuts(Object o)
   at System.Management.ManagementScope.Initialize()
   at System.Management.ManagementObjectSearcher.Initialize()
   at System.Management.ManagementObjectSearcher.Get()
   at Get_Computer_names.Program.Main(String[] args) in C:\Users\a_user\
Documents\Visual Studio 2010\Projects\program_name\program_name\Program.cs:line 77

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Something is wrong with your use of the try/catch as the error shouldn't say "unhandled exception."  That message means there was an error thrown and not caught.  Possibly you are catching something too specific and you just want to do this at the highest level

try
{
 main code here

}
catch(Exception ex)
{
     display some error message
}

and then at a lower level where you poll the machines:
foreach machine
  try
  {
    normal polling of the machine here
  }
  catch(Exception ex)
  {
    somehow indicate you couldn't reach this machine
  }
}

Author

Commented:
Thanks mastoo, makes sense, i'll give it a go on Monday :)

Author

Commented:
Clear and concise answer, Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial