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

故事扮演 提交于 2019-12-07 13:15:57

问题


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.:


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1306262/inspecting-an-instance-of-a-com-interop-class-properly-in-vs-nets-debugger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!