The Add Reference Dialog is the Wrong Scenario

There’s been complaints, in some for or another, about the Visual Studio Add Reference dialog since it’s creation.  Some are very well founded.  Defaulting to the .NET tab then spending many seconds high-jacking the UI while it loads the list is not a good experience.  VS 2010 takes a step forward and puts the work to enumerate the assemblies on a background thread and changes the default tab.

But, there’s still complaints about the dialog and the .NET tab.  Some complain that assemblies aren’t added in alphabetical order so it’s difficult to do anything until the list is entirely loaded.  Others complain that the list “jumps around” making it hard to read.  Some of these complaints might be solved by not sorting the list.

But, I believe, no matter how “good” anyone makes this dialog, a scenario that includes an Add Reference dialog to resolve a type that’s contained in a GAC assembly, or in another project in the current solution is inherently flawed in terms of a user experience.

The GAC is essentially a database of assemblies, and an assembly is partially a database of types.  Ergo, the GAC is a potential database of types.  I shouldn’t need to tell Visual Studio what assembly to use for types within the GAC, it should just look it up.  I don’t care what assembly contains the type, there’s no value to me having that knowledge or finding it out, I simply want to use that type.

I propose, rather than spending many resources on the Add Reference dialog, that Visual Studio attempt to automatically find the assembly that hosts types that it doesn’t have an assembly reference for.  This doesn’t have to be automatic; it could be an option for unknown type errors, like a “Find and add reference” smart tag item.  When I select that item I would then enumerate types in assemblies in the GAC that apply to the target framework for the project I’m trying to use the type within.  If the assembly is found in the GAC or in the current solution, add a reference to it the assembly or the project.  This data could be cached (either in memory or on disk) to make subsequence searches faster.  If the type can’t be found, bring up a browse dialog to browse for the file. 

Essentially, the fact that a type is contained within an assembly is simply an implementation detail that I shouldn’t need to deal with to write software in .NET.

12 thoughts on “The Add Reference Dialog is the Wrong Scenario”

  1. That’s a good point! However what should the behavior be when there are several assemblies with that exact type? (e.g. several versions)

    Show a list of them all and ask the user to pick one?

  2. I totally agree.

    The 2010 RC add reference dialog is useless until it is fully loaded. Because you cannot scroll nor select anything while it is loading.

    The add reference should more be like this:

    1. Type Partial Name of the class here.
    2. Select any of the declaring assemblies.

    And this should be also done within intellisense/refactoring option.

  3. @Kirill: yes, show a list lf mathcing types and require the user to pick one.

    Visual Studio should auto-pick based upon the current usings in the file or whether the type name was fully qualified.

    For example if I had “using System.Drawing” in my C# file (and didn’t yet have a reference to System.Drawing.dll) and later in the code I typed “Point point = new Point(1,42);”, VS should match on System.Drawing.Point first. If only one is found, add that reference. If multiple System.Drawing.Point types were find, prompt the user. If System.Drawing.Point wasn’t found, find Point in other namespaces–if only one is found, add it. If it found Point in multiple namespaces, request the user pick which one they want.

  4. @zproxy: yes, it’s hard to click on an entry in a list when the list is changing. I think not sorting the list would address that issue. In the meantime, I just type the assembly I’m looking for. For example “System.Drawing” would go to System.Drawing.dll if it had been loaded, even if other assemblies were still being added to the list. I could then press Enter to accept that assembly even if the list wasn’t fully populated.

    If there was an ability to automatically find an assembly based on an unknown type in code, there could be a UI that interfaced to that base functionality as you’ve described. That would be a better option to the current add references dialog. I prefer doing things from the code editor…

  5. I agree that dialog is quite annoying and something needs to be done. In fact i would also say that Projects tab is also quite annoying. Forgetting about the global reference(GAC) least visual studio should have the capability of finding the local references(i.e. with in same solution files).
    Since we are criticizing we should give ideas as well. I have an idea on revamp of the AddReference dialog. I think this should be there on the Global level i.e. on the context menu of Solution rather than project. This option could act as a cache of references, this would also include all the references of all the projects in the same solution file(i.e. automatically) as well. So once added to this cache then we can refer in multiple projects WITHOUT the need of adding same reference more than one time. One idea is to make smart tag(as proposed by Peter) more efficient and less complex.

  6. [Re-Submitting, had errors in first attempt]
    I agree that dialog is quite annoying and something needs to be done. In fact i would also say that Projects tab is also quite annoying. Forgetting about the global reference(GAC) least visual studio should have the capability of finding the local references(i.e. with in same solution files).
    Since we are criticizing we should give ideas as well. I have an idea on revamp of the AddReference dialog. I think this should be there on the Global level i.e. on the context menu of Solution rather than project. This option could act as a cache of references, this would also include all the references of all the projects in the same solution file(i.e. automatically) as well. So once added to this cache then we can refer in multiple projects WITHOUT the need of adding same reference more than one time. One idea is to make smart tag(as proposed by Peter) more efficient and less complex.

  7. Remember that the Add Reference dialog does not simply show assemblies in the GAC, even in the .NET tab. For example, install multiple versions of NUnit, and you will find multiple copies of nunit.framework.dll in the .NET tab, even though none of them are in the GAC. In that situation, what should happen if I apply the TestFixture attribute to a class?

  8. @David. If VS has a conflict, it should prompt the user how to resolve the conflict showing only the assemblies (and their location and version information) that could possibly match.

  9. While they are at it, why have they never bothered to removed assembly references that are not being used once you compile? It just adds noise in the References list.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>