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

First of all: I am a complete beginner.in COM.

I work as a team on a large project. Part of the server is written in C ++. The client side is written in C #. They communicate through COM.

Now - I have an IA interface in C #. And I have an o object whose type is class A (implements IA in C ++ - it is somehow transported through COM). I want to use reflection to get all the properties of this type, but it does not work properly. It returns only those properties that I 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 } } 
At first I thought this was not working due to COM. But it is strange that it gives me all the properties that I mention in the code. And all the material around COM should be written correctly, because it works for a long time (before I got into this project).
+4
source share
2 answers

The problem was the types of Interbed interop. I switched from True to False and worked.

+1
source

This may help you: Using Reflection with COM Interop

This will only help if you know the possible parameters for the property name, if you do not know, but want to list them, you may need to dive into the tlb file. A good example of how to load typelib and get the AssemblyBuilder class can be found here . The AssemblyBuilder.GetExportedTypes method must return all types defined in the TLB, and then you can use reflection for these types.

I struggled with this, so if you earn it, perhaps you could post a solution here.

+1
source

Source: https://habr.com/ru/post/1380002/


All Articles