Alex Janzik
Alex Janzik

Reputation: 3842

Visual Studio: Find the assembly of a class

Me stupid.

How can I know which assembly to reference if I just know the name of the class, for example System.Collections.Specialized.StringCollection.

(Yes, I know that more often than not I can make an educated guess by looking at the namespace.)

Thanks

Alex

Upvotes: 8

Views: 4851

Answers (4)

Korusef
Korusef

Reputation: 671

Tested in VS 2008:

  • in Class View search for the class you need assembly for
  • right click and select "Browse Definition"
  • in the Object Browser window toolbar click on the icon "Add to References in Selected Project in Solution Explorer"

EDIT:

  • Or you can just open the "Object Browser" from the View menu instead of the first two steps and do search for the class directly in the Object Browser window.
  • Does not work all the time. Sometimes the "Add" fails with unspecified error. Happens if the project name in VS does not match the assembly name. In that case you will have to look into that project and figure out where its .dll files are.

Upvotes: 3

Arvin Baccay
Arvin Baccay

Reputation: 162

What I usually do is right-click the "StringCollection" in the editor and click "Go To Definition" then a window will pop up with the title "StringCollection [from Metadata]" then I just hover the mouse pointer to the title and a tooltip appears with the location of the assembly where the class comes from.

Upvotes: 10

Micah
Micah

Reputation: 116220

Usually you can't since most assemblies contain multiple namespaces. Take the example of the System.Core.dll that was added in .net 3.5. It added additional classes to System.Collections.Generic. Some of the original classes lived in the mscorlib.dll One quick way to find out though would be to open up the "Object Browser" tab in VisualStudio, and click the little "Settings" toolbar button, and makes ure "View Containers" is checked.

Upvotes: -3

Dirk Vollmar
Dirk Vollmar

Reputation: 176269

You can check in MSDN: The assembly containing the class is mentioned right at the top:

StringCollection Class

Represents a collection of strings.

Namespace: System.Collections.Specialized

Assembly: System (in System.dll)

Upvotes: 7

Related Questions