top of page

C# | Assembly, EXE and DLL

For a beginner in the C# world, it will be very difficult to understand what it means. Let me put it in simple word, the assembly is nothing but it is precompiled chunk of .NET code which can be run by the CLR.


For a better understanding please have a look at the following diagram.



For example, here we have a very simple console app.



When I build this console app, we can see the precompiled chunks in the bin/debug/netcoreApp folder. What the building process actually does is to put this whole thing into a single EXE unit. (Note: for a better understanding of the concepts, let’s ignore the others files).



As a single unit of deployment, we can just copy this EXE file without copying the other files and put it on our production environment. So the assembly is nothing but it its the single unit of deployment, or if you put in simple words it is the chunk of code it is the precompiled chunk of code which can be executed by the CLR.


Now an assembly can be of various types for example we just saw assembly which is the EXE a executable. And the other kind of assembly is DLL.


For example, if I go and add a project of type class library, it becomes a DLL.



And if we build this class library and go the classLibrary/bin/Debug/netcoreapp folder, we will see the precompiled code of this class library.



So now in my solution, I have two assemblies, one is the type of EXE which is from my console app and the other is the type of DLL which is from the class library.


The Difference of EXE and DLL

DLL stands for Dynamic Link Library and EXE is nothing but the executable.


An EXE assembly actually runs in its own address space while a DLL can not run by itself. It doesn’t have its own address space, which means it has to run inside some host and needs a consumer to invoke it. For example, we can use the class library as a reference (dependency) in the console app.


Since EXE uses its own address space, it can be executed multiple times. For instance, if I clicked the EXE executable four times, the operating system will start 4 separate processes to run these applications.



Why do we have the concept that the EXE has its own address space and the DLL has to run in some other host? The whole point here is nothing but reusability. By using class library for example, we can easily reuse it in some other projects. We can just create the DLL once, and then reuse it in a console application, a windows application or a .NET application etc.


However, we need to know that DLLs will not be shared. If two processes use the same DLL, each process would have its own copy and the stored data of the declarations in the DLL will not interfere the values of the DLL in other processes.


Conclusion

I hope you enjoy this session. In this session, we are trying to understand what is the Assembly, what is the EXE and what is the DLL.



Source: Medium - The Crazy Coder


The Tech Platform

0 comments

Recent Posts

See All

Commentaires


bottom of page