Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable native code debugging to deep into COM-object

I have some code that uses a 3rd-party lib (ArcObjects) exposed by COM. So for instance there´s the IGeometry-interface.

IGeometry geometry = GetGeometry();

Now when I want to look at the objects members I open a QuickWatch:

enter image description here

I´ve read several issues that all point to the "enable native code debugging"-option in Visual Studio 2015. I´ve already enabled that option to no avail.

How can I get the debugger to expose the members of the COM-object?

EDIT: When working with VS2010 and .NET 3.5 this works:

enter image description here

like image 520
MakePeaceGreatAgain Avatar asked May 22 '18 11:05

MakePeaceGreatAgain


People also ask

How do I enable native code debugging?

Enable native code debugging in the properties. For C#, select Debug in the left pane, select Open debug launch profiles UI, then select the Enable native code debugging check box, and then close the properties page to save the changes.

How do you Debug a COM object?

In visual studio if you open tools >> Options and then debugging >> General make sure the option "Use managed compatibility mode" it checked on. This should show com objects as their proper types in the debugger.


1 Answers

Enabling unmanaged debugging can only have a useful side-effect if you also have the PDB and the source code for the component. You don't, vendors of these kind of components don't disclose it. The only reason you can see anything at all is because you let VS generate the interop assembly for the COM component. Which converts the declarations in the type library for the component into equivalent .NET types. Like IGeometry, most probably actually a C++ class under the hood.

Which is the big difference between the top view and the bottom screen-shots. Starting with VS2010 and .NET 4.0, this interop assembly is no longer needed. Called "type embedding", in general a highly useful feature, it avoids the need to deploy the PIA for a component. A very big deal in particular for Office interop.

Type embedding aggressively removed types and members that are not used in the source code. What is left is embedded into your final assembly, thus removing the need to deploy the interop assembly or PIA. Or in other words, you can't see IGeometry.Envelope back in the debugger because your source code doesn't use the property. It got stripped by the type embedding plumbing.

That is easy to fix. Select the COM reference in your project's Reference node and set its "Embed Interop Types" property to False. You can leave it that way after testing, don't forget then to also deploy the interop assembly.

like image 165
Hans Passant Avatar answered Oct 21 '22 07:10

Hans Passant