Therefore, very few objects are successfully instantiated and make remote procedure calls without any problems, But sometimes it raises exceptions, such as RPC Server cannot be used.
The COM component I am using is written in VB, and I use it in c#.
So, anyone Can tell me the possible cause of the problem (RPC server is unavailable) and the method to solve this problem.
I am very helpless with this problem now.
So, if you can help me, Thanks
So, I use the following methods to overcome this problem
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 the COM instance cannot be called, configure Instance and reinitialize COM and get the instance, then call RPC Server.
I am using COM Interop, I am instantiating COM class objects from interop dll
So, Few objects are successfully instantiated and make remote procedure calls without any problems, but sometimes exceptions are thrown, such as RPC Server cannot be used.
The COM component I am using is written in VB, and I use it in c# This component.
So, anyone can tell me the possible cause of the problem (RPC server is unavailable) and the way to solve this problem.
I am now about this problem Very helpless.
So, if you can help me, please thank you
After reviewing my COM implementation method, I found This bug. I use a static class to initialize the COM instance, the initialization thing happens in the static constructor. Therefore, each application session must be initialized once. In this case, when the COM instance is destroyed or discarded , Calling the COM method will cause an exception (RPC Server is not available).
So, I use the following methods to overcome this problem
try
{
m_COMObject.SomeMethod();
}
Exception(exception exception)
{
DisposeCOMObject();
InitializeCOMOBject();< br /> COMObject.Somethod();
}
public void DisposeCOMObject()
{
m_COMObject = null;
var process = Process.GetProcessesByNames("COM .exe").FirstDefault();
if(proce ss != null)
{
process.kill();
}
}
public void InitializeCOMObject()
{
m_COMObject = null;
m_COMObject = new COMObject();
}
If the instance of COM cannot be called, configure the instance and reinitialize COM and get Instance, then call RPC Server.