Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is an Assembly in C# or .NET?

People also ask

What is an assembly in C?

An assembly is a file that is automatically generated by the compiler upon successful compilation of every . NET application. It can be either a Dynamic Link Library or an executable file. It is generated only once for an application and upon each subsequent compilation the assembly gets updated. Copy link CC BY-SA 2.5.

What does assembly mean?

Assembly is used to refer to a group of people who have gathered together. Usually, the people have a reason to come together such as for religious, political, or social purposes. Assembly can also refer to the gathering or coming together of people, as in The principal organized an assembly of all of the parents.

What is inside an assembly?

An assembly is basically just a DLL or EXE file. It contains IL code and type information that describes the code in that DLL or EXE. It can contain a lot of other stuff too, but for starters just think of it as a DLL.


An assembly is the compiled output of your code, typically a DLL, but your EXE is also an assembly. It's the smallest unit of deployment for any .NET project.

The assembly typically contains .NET code in MSIL (Microsoft Intermediate language) that will be compiled to native code ("JITted" - compiled by the Just-In-Time compiler) the first time it is executed on a given machine. That compiled code will also be stored in the assembly and reused on subsequent calls.

The assembly can also contain resources like icons, bitmaps, string tables and so on. Furthermore, the assembly also contains metadata in the assembly manifest - information like version number, strong name, culture, referenced assemblies and so forth.

In 99% of your cases, one assembly equals a physical file on disk - the case of a multi-file assembly (one assembly, distributed across more than a single file) appears to be a rather odd-ball edge case which I've never encountered so far in my 5+ years of .NET development.

In a multifile assembly there would still be only one assembly manifest in a DLL or EXE and the MSIL code in multiple netmodule files.


.NET assembly

In the Microsoft .NET framework, an assembly is a partially compiled code library for use in deployment, versioning and security.


http://www.codeguru.com/columns/csharp_learning/article.php/c5845

An assembly is a file that is automatically generated by the compiler upon successful compilation of every .NET application. It can be either a Dynamic Link Library or an executable file. It is generated only once for an application and upon each subsequent compilation the assembly gets updated.


The answer is in order for immediate-grasping.

Put simply, it is the compiled project involving your classes and additional files, if there are. That is, each project in a solution is assembly.

Or more techinally,

An assembly is where a type is stored in the flesystem. Assemblies are a mechanism for deploying code. For example, the System.Data.dll assembly contains types for managing data. To use types in other assemblies, they must be referenced. - Source

How do we know it? If you glance at properties of a project under the solution you can see the following images.

When you compile the project, it turns out to DLL or EXE.

enter image description here enter image description here enter image description here


Here's another explanation of the make up of .NET Assemblies, a mini-quote:

The .NET framework consists of the concepts of modules, assemblies, which both store metadata and manifest information. An assembly can contain multiple modules. Visual C# only ever creates one module which is turned into an assembly by the C# compiler (csc.exe), but an assembly can link many .NET modules together via the assembly linker (al.exe) command-line tool. For example each of your source code .cs files could be compiled into a module and linked together to form an assembly - an assembly is just a collection of modules and resources. One of these modules, however; must contain manifest metadata (see below) information for the assembly to be understood by the CLR.
....
Having created a new .exe or .dll inside VS.NET you see your file appear inside your bin folder. Opening it in notepad will give out gibberish, or even inside a hexadecimal editor without knowing the structure of the file, you need a tool like ildasm.exe or CFF explorer to make meaning from it. The structure of the assembly is as follows:

PE header
CLR header
CLR metadata
CLR
IL code
Native data


When a source code is compiled by the language compiler it Generate a Managed Assembly and MSIL(MisroSoft Intermediate Language). That Assembly contains .dll or .exe file. An Assebmly can be of two types Private Assembly and Shared Assembly, shared Assembly is stored in GAC(Global Assembly Cache) so that any application can refer to it while private assembly is stored in application folder which can be used by only one Application.