Namespace or Assembly?

48,201

Solution 1

System.Data is a namespace, System.Data.DLL (the file) is an assembly.

A namespace is a logical grouping of types (mostly to avoid name collisions). An assembly can contain types in multiple namespaces (System.DLL contains a few...), and a single namespace can be spread across assemblies (e.g. System.Threading).

Solution 2

Namespace is a logical grouping of classes belongs to same functionality. So System.Web and System.Data are namespaces

MSDN describe it as:

Namespaces are heavily used in C# programming in two ways. First, the .NET Framework uses namespaces to organize its many classes Secondly, declaring your own namespaces can help control the scope of class and method names in larger programming projects.

namespace

Assembly is chunk of (precompiled) code that can be executed by the .NET runtime environment. It contains one or more than one Namespaces. A .NET program consists of one or more assemblies.

System.Web.dll and System.Data.dll are assemblies.

MSDN describe it as:

Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly.

assembly

Solution 3

In short:

Assembly:

An assembly provides a fundamental unit of physical code grouping.It is an Output Unit. It is a unit of Deployment & a unit of versioning. Assemblies contain MSIL code.

Namespace:

A namespace provides a fundamental unit of logical code grouping.It is a Collection of names where in each name is Unique.They form the logical boundary for a Group of classes.Namespace must be specified in Project-Properties.

Solution 4

In short:

  • Assembly is stored as an .EXE or .DLL files.
  • Namespace is a way of grouping type names and reducing the chance of name collisions.

Tips.

An assembly contains a collection of types (for example l'assembly System contains many namespaces included System, System.IO, ecc). Usually, the name of assembly is the same of a namespace that it contains but not always.

Other example of assemblies and namespaces.

Assembly 1 (CoreAssembly.DLL)

Contains namespaces Namespace1.subnamespace1

Assembly 2 (ExtensionCoreAssembly.DLL)

Contains namespaces Namespace1.subnamespace1

It is possible use name of assembly that contains different namespaces and extend an existing assembly with an other assembly by this technique.

DEFINITIONS.

Assemblies

An assembly is a collection of types and resources that forms a logical unit of functionality. All types in the .NET Framework must exist in assemblies; the common language runtime does not support types outside of assemblies. Each time you create a Microsoft Windows® Application, Windows Service, Class Library, or other application with Visual Basic .NET, you're building a single assembly. Each assembly is stored as an .exe or .dll file. Note Although it's technically possible to create assemblies that span multiple files, you're not likely to use this technology in most situations.

Namespaces

Another way to organize your Visual Basic .NET code is through the use of namespaces. Namespaces are not a replacement for assemblies, but a second organizational method that complements assemblies. Namespaces are a way of grouping type names and reducing the chance of name collisions. A namespace can contain both other namespaces and types. The full name of a type includes the combination of namespaces that contain that type.

Link: http://msdn.microsoft.com/en-us/library/ms973231.aspx

Solution 5

They are namespaces.Assemblies contains more than one namespace.For Example: System.dll contains these namespaces (and more):

enter image description here

Also one namespace might contain nested namespaces.They are just logical names to organize the code.Just be aware, a DLL files are assemblies that contains namespace(s).

GAC is Global Assembly Cache. According to MSDN:

The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.

So commonly used assemblies stored in the GAC and therefore you don't need to copy all assembly files to your project directory that you are referencing from your project.The assemblies stored in the GAC are Strong-Named assemblies.Normally when you add a reference to an assembly from your project that is not Strong-Named a copy of your .dll file will be created on your bin\Debug folder..If you wish you can make your assembly (class library project for example) Strong-Named.See: How to: Sign an Assembly with a Strong Name

Share:
48,201
user3125433
Author by

user3125433

Updated on November 28, 2020

Comments

  • user3125433
    user3125433 over 3 years

    I am getting very confused between Namespaces and Assemblies. Are System.Data and System.Web Namespaces or Assemblies?

    I have noticed these are called namespaces and at the same time they are present in GAC_32 folder. So what exactly are they?

  • Jugal Thakkar
    Jugal Thakkar over 10 years
    Two ways? Where's the second? :)
  • Zaheer Ahmed
    Zaheer Ahmed over 10 years
    @JugalThakkar added it too. see here for more details.
  • Concrete Gannet
    Concrete Gannet almost 9 years
    To put it slightly differently: namespaces have two purposes. One is to give a hierarchical "table of contents" for types, so you can locate or discover them more easily. If you can remember the name of the namespace, IntelliSense gives you a short list of its types. The second purpose is to manage and avoid name clashes. If you can avoid the namespaces "System", "Microsoft" and "Windows", you know none of your types will ever clash with Microsoft's.
  • Ehsan Sajjad
    Ehsan Sajjad over 7 years
    how do we specify which namespace to be in which assembly?
  • D Stanley
    D Stanley over 7 years
    @EhsanSajjad There's not a direct relationship between the two. An assembly is built from code files (usually via a project), each of which contains classes that are in a namespace. So you indirectly decide that by choosing which files are in a project. If that doesn't help then feel free to ask a new question.
  • Ehsan Sajjad
    Ehsan Sajjad over 7 years
    it makes sense. Thanks!!
  • eaglei22
    eaglei22 over 6 years
    So who or what determines more than one assembly? I create a project with a bunch of namespaces. What decides how many assemblies are created and what namespaces go under what assemblies?
  • Concrete Gannet
    Concrete Gannet over 5 years
    @EhsanSajjad, by using the C# namespace statement (or equivalent in another .NET language) in the source code that is compiled to create your assembly. Note it is possible for a second assembly to re-open a namespace and add more classes into it.