Question

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?

Was it helpful?

Solution

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, obj, args);

In .Net 4 something like this

Type myType = Type.GetTypeFromProgID("IMyLib.MyClass");
dynamic obj = Activator.CreateInstance(myType);
obj.MyMethod("Hello", 3);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top