zacharmarz
zacharmarz

Reputation: 213

Reflection in C# not working with COM (and C++)

First of all: I'm total beginner.in COM.

I'm working in team on big project. The server part is written in C++. The client side is written in C#. They communicate through COM.

Now - I have interface IA in C#. And I have object o, whose type is class A (implements IA in C++ - it is somehow trasfered via COM). I want to use reflection to get all properties of that type, but it's not working properly. It returns just those properties, which I have used in my code.

Here is the Reflection code that retrieves the properties:

Type[] ifaces = typeof(A).GetIterfaces();
foreach (Type iface in ifaces)
{
   foreach (PropertyInfo info in iface.GetProperties())
   {
       // it takes only those properties, I have used in C# code
   }
}

First I thought it's not working because of COM. But it's weird, that it gives me all properties, which I mention in code. And all stuff around COM should be written correctly, because it's working for a long time (before I got to this project).

Upvotes: 4

Views: 350

Answers (2)

zacharmarz
zacharmarz

Reputation: 213

The problem was in Embed interop types. I switched from True to False and it's working.

Upvotes: 1

zmilojko
zmilojko

Reputation: 2135

This might help you: Using Reflection with COM Interop

This would help only if you know possible options for the property name, if you have no idea but want to list them, you might have to dive into the tlb file. Good example on how to load a typelib and get the AssemblyBuilder class you can find here. AssemblyBuilder.GetExportedTypes method should return all types defined in TLB, and then you can use reflection on those types.

I have been struggling with this, so if you get it working, maybe you could post a solution here.

Upvotes: 1

Related Questions