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.:
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.
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.
The second one completely hides the "System.__ComObject". Click to view the full sized image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With