Introduction to .Net Libaries and Runtime BaseClassLibrary-vs-CLR-CoreFx-vs-CoreClr

Base Class Library v/s CLR:

The .Net Framework Base Class Library is the base foundation for developing applications, components and Controls as it exposes Several APIS implemented in different namespaces like System.IO, System.Globalization and many more. Under the hood, the actual component that has been refereed to Base Class Library is called MSCORLIb.dll. The actual source has been made open source and is available here https://referencesource.microsoft.com/#mscorlib,namespaces.

To understand this a bit more, let’s see what happens when I create a file from my asp.net web page using the below code.

bcl1.png

I attached a debugger to see how File Creation happens from my Page_Load function, and in the below stack we can see it ultimately calls a File Create API which is in MSCORLIB and which in turn would make a native call to OS through kernel32!CreateFile API.

bcl2.png

CLR : Common Language Runtime:

Your application code/base class library calls all run on an environment called CLR. The .net framework by default sits in the folder C:\Windows\Microsoft.NET\Framework64\v4.0.30319 and it has a dll called clr.dll which can be seen below

bcl3.png

The clr.dll is the runtime library and implements most functionality including Garbage Collection, Memory Management, Thread management.

Now, let’s look at same of the stacks in action when CLR runtime is handling the above functionalities.

Thread Management: The previous stack that you saw wasn’t complete, but here you can see at the bottom of stack how CLR runtime handles the thread required to execute your code.

bcl4.png

Garbage Collection: In the below thread the system.xml needed more space and that allocation was handled through CLR.

bcl5.png

CoreFx vs CoreClr:

Base Class Library is for applications targeting full .Net Framework but for asp.net core applications the base class library is called coreFx and in this image we can see how they fit to each framework.

bcl6.png

The CoreFx is fully open Source and is available on GitHub https://github.com/dotnet/corefx

When you install .net core , all different versions sit in a default location C:\Program Files\dotnet\shared\Microsoft.NETCore.App

bcl7.png

In the below picture you can see the CoreFx libraries (System.Collections. System.IO etc)

bcl8.png

And here is the CoreClr dll which implements multiple functionalities including GC

bcl9.png