t3dodson
t3dodson

Reputation: 4007

How to know what assembly to add C#

I've ran into this issue a couple times and I'm wondering if anyone has a better solution than trial and error or searching stack overflow.

Lets say we are using some .net class Foo

Foo resides in the Bar.Baz namespace

The following statement

using Bar.Baz;

is not sufficient to compile the program, we are missing an assembly reference. So add a reference to System.Bar.Baz It still doesn't work so after searching the internet I find that I actually have to add a reference to Some.Other.dll and now it compiles.

My question is how do I know what namespace maps to what reference when the usual one doesn't work?

Most recent problem was The type or namespace name 'DbContext' could not be found Instead of adding a reference to System.Data.Entity I had to install through Nuget.

Upvotes: 0

Views: 197

Answers (2)

Thiago Sá
Thiago Sá

Reputation: 852

If you're using Visual Studio 2013 or higher, one easy way to discover which namespace a class belongs to is using the Peek definition feature. You can easily find it in the right-click context menu.

In the screen below, I used it with KeyValuePair:

Peek definition screenshot

Also, take a look at the documentation.

Upvotes: 0

David S.
David S.

Reputation: 11178

If it is a .NET framework function, you can just search it on MSDN, and it will tell you in which assembly the class/function exists.

You can also use ReSharper which is a very nice plugin to Visual Studio, and it can help you add assemblies automatically.

Upvotes: 3

Related Questions