Problem in COM Late-binding when exposing assembly to COM

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I am having a serious trouble when calling a .NET Assembly from a NON-CLR
app (VB6 app) through Com Wrapper. The object creation is fine; but when I
try to call its method it says "Object doesn't support this property or
method: 'MethodName'" .

If I add reference to the TLB and do with COM Early binding, it works. How
to get Late-binding client working ?

Here is the first method that works: Tlb file is added in references of VB
project

Dim obj As IMyAssembly
Set obj = CreateObject("My.Namespace.MyAssembly")

obj.DoSomething(); //working fine cheers!



Here is the second method that doesnt work: Tlb file is not added in
references of VB project

Dim obj As Object
Set obj = CreateObject("My.Namespace.MyAssembly")

obj.DoSomething(); // doesnt work :( says 'Object doesnt support this
property of method 'DoSomething''

I guess I need to supply the "default property" of object or "default
interface" of object but i dont know how to do it in .NET C#.


Any help on this will be appreciated.

Fahad Ashfaque
 
I don't know exactly what the VB CreateObject does, but in late binding you
don't call nethods directly. In C# I use a class to do this:

public class CreateObject
{
private Type comType;
private object comObject;

public CreateObject(string ProgID)
{
comType=Type.GetTypeFromProgID(ProgID);
comObject=Activator.CreateInstance(comType);
}
public CreateObject (string ProgID, string theServer)
{
comType=Type.GetTypeFromProgID(ProgID, theServer);
comObject=Activator.CreateInstance(comType);
}
public object Execute(string Method, params object[] Parameters)
{
return comType.InvokeMember(Method, BindingFlags.InvokeMethod, null,
comObject,Parameters);
}
}
and then use

CreateObject swu = new CreateObject ("your progid");
object res = swu.Execute ("DoSomething", null);

all assuming the Progid is registered etc. HTH.
 
Back
Top