Unable to cast COM object to interface type 'WUApiLib.UpdateSession c#


I am using WUApiLib.dll, and writing a program to detect which updates can be downloaded and installed.

    Type t = Type.GetTypeFromProgID("Microsoft.Update.Session", "");
    UpdateSession session = (UpdateSession)Activator.CreateInstance(t);

    ISearchResult SearchResults = UpdateSearchResult.Search("IsInstalled=0");
    foreach (IUpdate x in SearchResults.Updates)

most of the time it works perfectly, but in some cases I am getting an error in the casting to UpdateSession:

UpdateSession session = (UpdateSession)Activator.CreateInstance(t);

with the following error:

{"Unable to cast COM object of type 'System.__ComObject' to interface type 'WUApiLib.UpdateSession'. 
This operation failed because the QueryInterface call on the COM component for the interface 
with IID '{918EFD1E-B5D8-4C90-8540-AEB9BDC56F9D}' failed due to the following error: 
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)."}

I dont have firewall configured, as I saw people say in other topics regarding similar error, but I have no idea why I am getting this error. any idea what is the problem and how I can solve it?

asked on Stack Overflow Feb 19, 2017 by daniel the man

1 Answer


The RPC server is unavailable

The sometimes clause in the question is the normal behavior for this kind of error. Tells you that you don't in fact have a configuration problem. It is very low-level, your computer can simply not communicate correctly with the server.

A temporary networking problem.

It is the kind of problem you cannot recover from in your program, somebody needs to fix the network or get the server back online. So all you can do is let the user of your program know that right now your feature is unavailable.

Translating errors is not normally a good idea but this one is gobbledegooky enough to consider showing a more helpful diagnostic. Something opaque like "We're sorry, a temporary networking service interruption prevented us from contacting the server. Please try again later or contact IT staff to expedite the problem." If IT staff gets bugged about it often enough then they'll do something to make the network or server more reliable. Which is what it takes, better hardware, not better software.

answered on Stack Overflow Feb 22, 2017 by Hans Passant

User contributions licensed under CC BY-SA 3.0