Unable to pass COM object to interface type "WUApiLib.UpdateSession C #

I use WUApiLib.dll and write a program to determine which updates can be downloaded and installed.

Type t = Type.GetTypeFromProgID("Microsoft.Update.Session", "10.81.4.213"); UpdateSession session = (UpdateSession)Activator.CreateInstance(t); ISearchResult SearchResults = UpdateSearchResult.Search("IsInstalled=0"); foreach (IUpdate x in SearchResults.Updates) { Console.WriteLine(x.Title); } 

Most of the time it works fine, but in some cases I get an error message when releasing 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 don’t have a firewall setting since I saw people talking on other topics regarding a similar error, but I have no idea why I get this error. any idea what the problem is and how can i solve it?

+6
source share
2 answers

RPC server unavailable

Sometimes in a question, sometimes the usual behavior arises for this type of error. Tells you that you actually have no configuration problem. It is very low-level, your computer may just not properly communicate with the server.

Temporary network problem.

This is a problem that you cannot restore in your program, someone needs to fix the network or return the server in online mode. So, all you can do is let the user of your program know that right now your function is not available.

Error translation is usually not a good idea, but this method is good enough to consider the possibility of more useful diagnostics. Something opaque like "Sorry, a temporary interruption in network services did not allow us to contact the server. Please try again later or contact your IT staff to expedite this problem." If IT staff often worries about this, they will do something to make the network or server more reliable. This is what you need, the best hardware, not the best software.

+1
source

Verify that the Remote Procedure Call (RPC) service is running.

If it is running, it could be a firewall problem between your workstation and the server. You can test it by temporarily disabling the firewall and repeating the command.

Or it may be due to network connectivity issues between you and the target computer.

0
source

Source: https://habr.com/ru/post/1015100/


All Articles