anon
anon

Reputation:

Inspecting an instance of a COM / Interop class properly in VS.Net's debugger?

Does anyone know if and how it's possible to see COM / Interop objects properly (in their correct type) in VisualStudio's debugger? All I get is the 'evil' System.__ComObject value (even though it correctly identifies the type)?

E.g.:

Screenshot

Upvotes: 4

Views: 1946

Answers (3)

C-Pound Guru
C-Pound Guru

Reputation: 16368

From .NET and COM: The Complete Interoperability Guide:

When an instance of a COM object is returned to you, via a method's return type or a by-reference parameter, and the CLR can't determine the type, you'll get the generic System.__ComObject type because COM objects are always passed/returned as interface pointers.

You might try changing the return type using Marshal.CreateWrapperOfType as in the example below:

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

Then you can look at newObject in your watch window and it should have the expected properties.

If the call fails, it will throw an InvalidCastException.

Upvotes: 2

Yoopergeek
Yoopergeek

Reputation: 5642

So, this isn't an answer, but check out these two screen shots. This is from the same application, just at two different break points. In both cases the COM objects are from the same COM/AX library. I've no idea why in one case I see "System.__ComObject" and in the other the proper type. However, in both cases, I'm seeing the appropriate object/interfaces properties. What gives? Why the difference?

The first one here shows it showing up a "System.__ComObject", however it's also showing me all of the properites of the object. Click to view the full sized image.

alt text

The second one completely hides the "System.__ComObject". Click to view the full sized image.

alt text

Upvotes: 1

Randy Levy
Randy Levy

Reputation: 22655

I've used the immediate window to manually query the properties of the COM object. The downside is that I don't think you get intellisense so you have to know exactly what you want to inspect.

Upvotes: 1

Related Questions