Inspecting COM / Interop class instance properly in VS.Net debugger?

Does anyone know if and how one can correctly see COM / Interop objects (in their correct type) in the VisualStudio debugger? All I get is the "evil" System .__ ComObject value (even if it identifies the type correctly)?

eg:.

Screenshot

+2


source to share


3 answers


So, this is not an answer, but check these two screenshots. It's from the same app, just two different break points. In both cases, COM objects are from the same COM / AX library. I don't know why in one case I see "System .__ ComObject" and in the other the correct type. However, in both cases, I see the corresponding properties of the objects / interfaces. What gives? Why the difference?

The first one shows that it shows "System .__ ComObject", however it also shows me all the properties of the object. Click to view full size image.

alt text



The second completely hides "System .__ ComObject". Click to view full size image.

alt text

+1


source


From .NET and COM: The Complete Compatibility Guide :

When an instance of a COM object is returned to you using the return type of a method or a parameter to reference, and the CLR cannot determine the type, you get the generic type System .__ ComObject because COM objects are always passed / returned as interface pointers.

You can try changing the return type with Marshal.CreateWrapperOfType

as shown in the following example:



MyType newObject = (MyType)Marshal.CreateWrapperOfType(oldObject, typeof(MyType))

      

Then you can look at newObject in the viewport and have the expected properties.

If the call fails, it throws an InvalidCastException.

+2


source


I used the direct window to manually query the properties of a COM object. The downside is that I don't think you are getting intellisense, so you need to know exactly what you want to test.

+1


source







All Articles