209

What are .NET Assemblies? I browsed over the net and I am not able to understand the definition.

1
  • 11
    Have a read of CLR Via C#. You'll know all about it by the end. I highly recommend this book. Jun 4, 2010 at 9:17

13 Answers 13

263

Assembly is the smallest unit of deployment of a .net application. It can be a dll or an exe.
There are mainly two types to it:

  1. Private Assembly: The dll or exe which is sole property of one application only. It is generally stored in application root folder

  2. Public/Shared assembly: It is a dll which can be used by multiple applications at a time. A shared assembly is stored in GAC i.e Global Assembly Cache.

Sounds difficult? Naa....
GAC is simply C:\Windows\Assembly folder where you can find the public assemblies/dlls of all the softwares installed in your PC.

There is also a third and least known type of an assembly: Satellite Assembly.
A Satellite Assembly contains only static objects like images and other non-executable files required by the application.

2
182

In more simple terms: A chunk of (precompiled) code that can be executed by the .NET runtime environment. A .NET program consists of one or more assemblies.

2
  • 32
    @KimJongWoo - No, a Jar file is just a zip file that contains compiled bytecode files. An assembly is a PE (Portable Executable format) File (ie a DLL or EXE), but conceptually they serve similar purposes. Jun 9, 2013 at 7:53
  • So it is like a .class file in Java-world?
    – mljrg
    Jan 3, 2018 at 13:28
20

In addition to the accepted answer, I want to give you an example!

For instance, we all use

System.Console.WriteLine()

But Where is the code for System.Console.WriteLine!?
which is the code that actually puts the text on the console?

If you look at the first page of the documentation for the Console class, you‘ll see near the top the following: Assembly: mscorlib (in mscorlib.dll) This indicates that the code for the Console class is located in an assem-bly named mscorlib. An assembly can consist of multiple files, but in this case it‘s only one file, which is the dynamic link library mscorlib.dll.

The mscorlib.dll file is very important in .NET, It is the main DLL for class libraries in .NET, and it contains all the basic .NET classes and structures.

if you know C or C++, generally you need a #include directive at the top that references a header file. The include file provides function prototypes to the compiler. on the contrast The C# compiler does not need header files. During compilation, the C# compiler access the mscorlib.dll file directly and obtains information from metadata in that file concerning all the classes and other types defined therein.

The C# compiler is able to establish that mscorlib.dll does indeed contain a class named Console in a namespace named System with a method named WriteLine that accepts a single argument of type string.

The C# compiler can determine that the WriteLine call is valid, and the compiler establishes a reference to the mscorlib assembly in the executable.

by default The C# compiler will access mscorlib.dll, but for other DLLs, you‘ll need to tell the compiler the assembly in which the classes are located. These are known as references.

I hope that it's clear now!

From DotNetBookZero Charles pitzold

10

Wikipedia has to say:

In the Microsoft .NET framework, an assembly is a partially compiled code library for use in deployment, versioning and security. There are two types: process assemblies (EXE) and library assemblies (DLL). A process assembly represents a process which will use classes defined in library assemblies. .NET assemblies contain code in CIL, which is usually generated from a CLI language, and then compiled into machine language at runtime by the CLR just-in-time compiler. An assembly can consist of one or more files. Code files are called modules. An assembly can contain more than one code module and since it is possible to use different languages to create code modules it is technically possible to use several different languages to create an assembly. Visual Studio however does not support using different languages in one assembly.

If you really did browse it would help if you'd clarify what you don't understand

7

See this:

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

7

physical collection of Class, interface, enum etc which is in IL code. Which can be .EXE or .DLL file .EXE is executable file and .DLL can dynamically used in any .net Supported language.

7

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.

Source : https://msdn.microsoft.com/en-us/library/ms973231.aspx#assenamesp_topic4

For those with Java background like me hope following diagram clarifies concepts -

Assemblies are just like jar files (containing multiple .class files). Your code can reference an existing assemblie or you code itself can be published as an assemblie for other code to reference and use (you can think this as jar files in Java that you can add in your project dependencies).

At the end of the day an assembly is a compiled code that can be run on any operating system with CLR installed. This is same as saying .class file or bundled jar can run on any machine with JVM installed.

enter image description here

5

MSDN has a good explanation:

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.

2

In .Net, an assembly can be:

A collection of various manageable parts containing Types (or Classes), Resources (Bitmaps/Images/Strings/Files), Namespaces, Config Files compiled Privately or Publicly; deployed to a local or Shared (GAC) folder; discover-able by other programs/assemblies and; can be version-ed.

2

As assembly is the smallest unit of versioning security, deployment and reusability of code in Microsoft.Net.

It contains:

- Assembly Identity
- Manifest
- Metadata
- MSIL Code
- Security Information
- Assembly Header
1

Assembly is the fundamental part of programming with .NET Framework. It contain code that CLR executes MSIL(Microsoft Intermediate Language) code in a portable executable file will not be executed if it does not have an associated assembly manifest.

1

In .NET, when we compile our source code then assembly gets generated in Visual Studio. Assembly consists of two parts Manifest and IL(Intermediate Language). Manifest contains assembly metadata means assembly's version requirements, security identity, names and hashes of all files that make up the assembly. IL contains information about classes, constructors, main method etc.

1

Visual Studio solutions consists of one or more projects. For Example : Console projects can produce an assembly. An assembly is logically chunk of code that can be shipped to customers, and physically an .EXE (executable program) or .DLL (are reusable by other programs).