Is the namespace an assembly or a project?

Just browse some .NET interview material tomorrow.

MSDN defines the keyword Internal

as follows:

Internal types or members are only available inside files in the same assembly

But what I cannot find is the definition for the assembly. Is it all inside the same namespace, the same project, or ...?

+3


source to share


6 answers


Within an assembly, you can define multiple namespaces. An assembly is the smallest unit of deployment in .NET. This is a collection of your IL code and metadata about your code. It contains a Manifest file that declares all types that are used in your assembly or referenced. There are other files as well.

As stated more formally on MSDN :

Assemblies are the building blocks of .NET Framework applications; they form the main unit of deployment, version control, reuse, activations, and security permissions. An assembly is a collection of types and resources that are designed to work together and form a logical unit of functionality. An assembly provides a common language environment with information you need to know about an Implementation type. For the runtime, the type does not exist outside the assembly context.

On the other hand, for a namespace

we have that



The namespace keyword is used to declare a region that contains a set of related objects. You can use a namespace to arrange code elements and create globally unique types.

as stated on MSDN

From the above, it is clear that you can declare as many namespaces as you want within the assembly.

A good and free tool that you can use to see what's in an assembly is the IL Disassembler .

+4


source


An assembly is a project that has been compiled to a .DLL or .EXE. For Visual Studio targets, any class library project or Windows Forms application or WPF application will be compiled into an assembly.



+1


source


An assembly is a physical container file (DLL or EXE).

Although somewhat unusual, the namespace can span multiple assemblies.

+1


source


Inner classes are not necessarily visible to all classes in the same namespace because a namespace can span multiple assemblies. An assembly is a compiled file (DLL or EXE).

This usually means within the same project, but there are ways to combine the output of multiple projects into one assembly (via ILMERGE).

+1


source


Assemblies and namespaces are orthogonal. One assembly can contain multiple namespaces, and one namespace can span multiple assemblies. Assembly is the smallest independent version of code in the .NET platform. Assemblies define the physical organization of your code (in dll or exe files), and namespaces define the logical organization. A single assembly is one dll or exe file. A namespace is a logical grouping, usually based on technology or function. System.Net

works with the network. System.Text

deals with text manipulations and encodings.

Please note that I did not mention projects at all. A project is something really relevant to a specific build system. The .NET runtime is unaware of projects as such. Since most people use Visual Studio and MSBuild tools for development, and by default display one assembly per project, people usually use the terms "project" and "assembly" interchangeably in casual conversation. Other tools, such as MonoDevelop, follow a similar pattern, but there is no rule dictating that one project should create a single assembly.

+1


source


In the .NET world, an assembly is a package of compiled code. It can be an executable file ( .exe

) or a shared library ( .dll

file) and can contain multiple namespaces.

0


source







All Articles