Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I qualify a .NET type with assembly name for Visual Studio debugger to disambiguate while using an ambiguous type?

I am using the VS debuggers 'Immediate Window' to call a static API on a class which is an ambiguous type defined in 2 different assemblies.

The call fails with the following message: The type foo exists in both blah.dll and bar.dll

This message makes sense since this is indeed the case. My question is how can I work around this in the debugger to specify which assembly I want to be used for binding this type?

Is there a way to qualify a type with the assembly name that it is defined in?

Thanks Bhavin.

like image 362
bhavinb Avatar asked Oct 15 '09 12:10

bhavinb


People also ask

How do I catch exceptions in Visual Studio?

With a solution open in Visual Studio, use Debug > Windows > Exception Settings to open the Exception Settings window. Provide handlers that respond to the most important exceptions. If you need to know how to add handlers for exceptions, see Fix bugs by writing better C# code.

How do I set debug configuration in Visual Studio?

In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).

Which debugger button do you use to move execution a single line during debugging while not stepping into any other methods?

Press F5 until you reach the line of code where you selected Run to Cursor. This command is useful when you are editing code and want to quickly set a temporary breakpoint and start the debugger at the same time. You can use Run to Cursor in the Call Stack window while you are debugging.

How do I set debugger to mixed?

Enable mixed-mode debugging for a native calling appIn the <Project> Property Pages dialog box, expand Configuration Properties, and then select Debugging. Set Debugger Type to Mixed or Auto. Select OK.


2 Answers

It sounds like you have two types which have the same name and namespace but live in different assemblies? If that is the case, unfortunately there is no way to disambiguate this call in the immediate window. The immediate window considers both of these types to be in scope and since assembly name cannot be a part of the cast syntax in C# or VB.Net there is no way to disambiguate these types.

The only option you have is to create an alternate debug only API which binds to one or the other. Then call this during the debugging session.

like image 86
JaredPar Avatar answered Nov 02 '22 05:11

JaredPar


As Maslow suggests, it is possible to use reflection to get what you want. It's not pretty, though. For example, if you want to see the value of the static property My.Properties.Settings.Default, then assuming that MainWindow is some other type in the assembly (e.g. blah.dll) that contains the value you want to debug, this expression will get you the value:

System.Reflection.Assembly
    .GetAssembly(typeof(MainWindow))
    .GetType("My.Properties.Settings")
    .GetProperty("Default")
    .GetValue(null)

In this example, My.Properties.Settings is a type that is defined in two different assemblies.

It's also possible to call methods etc. by using the appropriate tools from the System.Reflection namespace.

like image 26
vvnurmi Avatar answered Nov 02 '22 05:11

vvnurmi