views:

122

answers:

1

Is there a manual way to call a COM object in the GAC in .NET, without adding it as a reference?

The reason I ask is I only know how to code in C# and want to call a .NET COM object and tests that its CMO calls are visible, but obviously you can't add a .NET COM object to a .NET assembly! As you have to reference it, so I was wondering can you call it if its registered in the GAC manually through c# code?

+5  A: 
Type myType = Type.GetTypeFromProgID("IMyLib.MyClass");
object obj = Activator.CreateInstance(myType);
object[] args = new object[2];
args[0] = "Hello";
args[1] = 3;
myType.InvokeMember("MyMethod", BindingFlags.InvokeMethod, null, args);

In .Net 4 something like this

Type myType = Type.GetTypeFromProgID("IMyLib.MyClass");
dynamic obj = Activator.CreateInstance(myType);
obj.MyMethod("Hello", 3);
ArsenMkrt
thank u so much!
David
Your C# 4.0 syntax is based on early (unreleased?) prototypes; however, I don't have VS2010B2 installed to give the correct syntax...I'm sure somebody else does.
Dan
I edited the post, I don't have vs 2010 installed too, but as I know this is a correct way to do that
ArsenMkrt