MarshalByRefObject remoting via Interfaces don't work in COM clien

G

Guest

This is a combined .NET Remoting & COM interop problem and I don't know which
is the culprit.

I have wrapped a .NET remoting client using the the COM wrapper (regasm,
etc) which fails when the remoting client receives an Interface-type, for
example:

public IMyTask GetRemoteTask()
{
IMyTask myTask;
myTask = (IMyTask) Activator.GetObject(typeof(IMyTask),
"tcp://localhost:8101/MyTask);
}

Calling this GetRemoteTask function from Excel/VBA fails with Error
-2147467262 "No such interface supported". This .NET function is exposed in a
COM dll after running regasm and doing all the other COM wrapper hocus-pocus.

Casting to the class rather than the interface fixes the problem, for example:

public IMyTask GetRemoteTask()
{
IMyTask myTask;
myTask = (MyTask) Activator.GetObject(typeof(MyTask),
"tcp://localhost:8101/MyTask);
}

This isn't the optimal solution because the implemenation now has to be
distributed in addition to the interfaces. I don't want to release or
distribute the implementation DLL which is a big problem.

Another post in dotnet.framework.remoting titled "MarshalByRefObject object
published..." lists exactly the same issue.
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

First things first - make sure IMyTask is marked as [ComVisible(true)] and
has proper [InterfaceType] attribute.
Then, when you activate a remote object, you actually get a proxy object...
and I am not sure it will properly implement the COM part. I'd still
recommend that you use two (apparently identical) interfaces - one for
remoting purposes, this one would not be visible to COM clients, and the
other will be exposed as a COM interface, but its implementation will just
delegate the calls to the remoting interface.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top