After reviewing my approach for COM implementation I found the bug. I was using a static class for initializing the COM instance and initialization stuff was taking place in static constructor. So, initialization was being done once per application session. In the case, when the com instance gets corrupted or is disposed, then making calling to COM methods throws exception (RPC Server is unavailable). So, I used following approach for overcoming the issue
try
{
m_COMObject.SomeMethod();
}
Exception(exception exception)
{
DisposeCOMObject();
InitializeCOMOBject();
COMObject.Somethod();
}
public void DisposeCOMObject()
{
m_COMObject = null;
var process = Process.GetProcessesByNames("COM .exe").FirstDefault();
if(process != null)
{
process.kill();
}
}
public void InitializeCOMObject()
{
m_COMObject = null;
m_COMObject = new COMObject();
}
if instance of COM is unable to make call then dispose the instance and reinitialize the COM and get instance, then make call to RPC Server.