COM+ invoking method in remote instance Unknown name error

2

I have a COM dll which I was using in my .net project through interop referance. Now I got a requirement to move this COM component to another remote machine and create instance there.(kind of out of machine similar to out of process, probably this is remoting, i don't know :-))

What I have done was created a new COM+ applciation in server machine. Added this component inside this app. This is how it is listed in COM+ interface on server. enter image description here

Exported this app as proxy insatller and installed in my client machine. Used following code to access this

Type type;
type = Type.GetTypeFromProgID("DllName.COMName", "serverName", false);
var COMObject = Activator.CreateInstance(type);
var returnValue = COMObject.GetType().InvokeMember("Method_1",   BindingFlags.Public |  BindingFlags.InvokeMethod, null, COMObject, new object[1] { "1" });

But I am getting UNKNOWN NAME (0x80020006) error when invoking Method_1? Have any one face similar issue before, please help me.

c#
.net
com
remoting
asked on Stack Overflow Aug 24, 2012 by Shanadas • edited Aug 30, 2012 by Shanadas

3 Answers

3

What I would do is this:

1) create an equivalent interface in C#, something like this:

[Guid("<the interface IID goes here>")]
public interface ISomeInterfaceName
{
   int Method1(...);
   int Method2(...);
   int Method3(...);
   ...
}

2) and then this, instead of your initial late-binding code:

Type type = Type.GetTypeFromProgID("DllName.COMName", "serverName", false);
var COMObject = Activator.CreateInstance(type);
var if = (ISomeInterfaceName)COMObject;
if.Method1(...);

NOTES: the IID must the IID from the interface, not to be confused with the CLSID. The methods should be laid out to correspond exactly to the COM ones (the methods order is important, how parameters and return type are defined is also important)

You could also import the TLB from the COM component, if you have a lot of classes and intefaces like this.

answered on Stack Overflow Aug 30, 2012 by Simon Mourier
0

You don't need to use GetType() when invoking the method. COMObject.InvokeMember() should be sufficient.

Also, try getting the Type from the ClassID - by using .GetTypeFromCLSID() - rather than ProgID.

Additionally rather than BindingFlags.Public use BindingFlags.Default. This will specify that all type members will be available.

answered on Stack Overflow Aug 30, 2012 by tom redfern • edited Aug 30, 2012 by tom redfern
0

If you have your application proxy correctly installed and configured in the client machine you should be able to instantiate your COM+ just as you create any other object instance.

Try just this:

IMyExpectedInterface o = new MyCOMServicedComponent();
o.SomeMethod();

If that is not running fine let me know the exception result you get while instantiating it.

answered on Stack Overflow Aug 30, 2012 by Luis Quijada

User contributions licensed under CC BY-SA 3.0