VS2017 debugging: Unable to access members of COM object

2

Issue

Normally, Visual Studio's "Dynamic View" displays an object's members. Occasionally, the object requires all threads to run and you manually have to allow that in order to see the members. However, with this COM object, I'm getting an error when I attempt to see the members:

Unable to evaluate the expression. Operation not supported. Unknown error: 0x80070057.


Details

Here are screenshots of the process:

  1. Viewing the COM object:

    1

  2. Viewing the COM object's members:

    2

  3. Opening Dynamic View results in:

    The function evaluation requires all threads to run.

    3

  4. When I click the refresh icon, the error changes:

    Unable to evaluate the expression. Operation not supported. Unknown error: 0x80070057.

    4


What I've tried

Besides inconclusive research on these two error messages, the only things I have tried are deleting the .suo file and restarting Visual Studio.

I know what data the API call returns because I am able to print the data to the console. However, not being able to view this data from the debugger is really slowing me down. Any help would be appreciated. Thanks!

c#
.net
debugging
com
visual-studio-2017
asked on Stack Overflow Jun 12, 2018 by Jake Reece • edited Jun 12, 2018 by Jake Reece

2 Answers

0

The following comment in this question from Hans Passant helped me find a solution:

You can usually cast it to one of the interface types supported by the component. Then the debugger gets smart again... iterate it with foreach. Actual underlying runtime type is a proxy, happens when you call the method from a worker thread or if it is an out-of-process server.

The solution is to iterate over the COM object first before trying to use it. So, if the COM object is a collection, iterate over the items, cast as an interface type, and store the result in a var or custom model.

Something like this:

var myObject = com.GetStuff().OfType<InterfaceClass>().Select(s => new { Name = s.Name, Description = s.Description });
answered on Stack Overflow Jun 12, 2018 by Jake Reece
0

In my case I was able to see the com objects types in the debugger by enabling the option "Use managed compatibility mode"

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.

answered on Stack Overflow Feb 1, 2019 by Dowlers

User contributions licensed under CC BY-SA 3.0