views:

64

answers:

4

This seems confusing to me - im creating a class library, and adding all the necessary references for the source files contained in it.

Now, off the bat, there were over 300 compiler errors complaining about missing namespaces. The library will now compile after i just added all of the System.* references, however this is obviously not the best way.

I.e. if a classes needs using System.Web.Script;, there is no System.Web.Script reference, how would i find out which one of these references contained it? System.Web didnt.

+2  A: 

Yes a namespace and an assembly are two different concepts in .NET ... They can, but don't need to share a common name.

Best thing is to inspect the type your missing in MSDN (hit F1 in Visual Studio when your text cursor is above a class that you're missing). The MSDN documentation will tell you which namespace and which assembly that type is defined in.

herzmeister der welten
+2  A: 

Well, the compiler will complain about missed classes, not missed namespaces. You have to look for the classes on the MSDN, there you will find the related namespace and assembly.

For instance for the DropDownList

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist%28v=VS.80%29.aspx

at the top you can read

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Timmy O' Tool
+1  A: 

Namespaces can be re-openwd so more than one assembly can define classes in one namespace.

// AssemblyFoo.dll
namespace MyNamespace {
    class Bar {}
}

// AssemblyBaz.dll
namespace MyNamespace {
    class Qux {}
}

For MyNamespace.Bar you need to reference AssemblyFoo.dll, for MyNamespace.Qux you need to reference AssemblyBaz.dll. You can't deduce the needed assemblies just from the namespace.

The best thing you can do it to look up where the class is defined using the MSDN.

helium
+1  A: 

You can also use the Object Browser in Visual Studio to click on a namespace, and it will show the assembly and the path to it. As long as the assembly is in the GAC or Visual Studio otherwise knows about it, you should be able to find it in there.

You can also type in "System.Web.Script" into the object browser's search box, and it'll find the namespace, which you can then right click and say "Go To Definition". It'll take you to the parent, which will be the namespace/assembly grouping, and you'll see the .dll that it resides in.

womp