Microsoft .
Net Framework
Master the Features of .Net Framework
Contents
.Net Framework ................................................................................................................................................. 2
Architecture of .NET Framework ................................................................................................................... 2
The Common Language Runtime .............................................................................................................. 2
Garbage collection ..................................................................................................................................... 3
Class Library ............................................................................................................................................... 5
Managed code ........................................................................................................................................... 5
Intermediate Language code ..................................................................................................................... 5
Finding Framework Versions ......................................................................................................................... 6
Assembly........................................................................................................................................................ 8
Private Assembly and Shared Assembly .................................................................................................... 8
Strong-named assemblies ......................................................................................................................... 9
Global Assembly Cache............................................................................................................................ 10
.NET Framework Stack ..................................................................................................................................... 11
Visual Studio .................................................................................................................................................... 12
Solution and Projects................................................................................................................................... 13
Yotta B o t B u s i n e s s S o l u t i o n s 1
15
Ravi Consultant & Corporate Trainer +91 8310068586
.Net Framework
.NET is a developer platform made up of tools, programming languages, and libraries for building many
different types of applications.
.NET Framework is a technology that supports building and running Windows apps and Web apps and
Services. (Windows services and Web services)
Supports different platforms—Linux, macOS, Windows, iOS, Android, and many more.
NET Core is a cross-platform implementation for running websites, services, and console apps on Windows,
Linux, and macOS.
Cross Platform: Whether you're working in C#, F#, or Visual Basic, your code will run natively on any
compatible OS.
Provides a consistent object-oriented programming environment whether object code is stored and
executed locally, executed locally but web-distributed or executed remotely.
To provide a code-execution environment that minimizes versioning conflicts. It Supports Side-by-Side
Execution - the ability to run multiple versions of an application or component on the same computer. You
can have multiple versions of the common language runtime, and multiple versions of applications and
components that use a version of the runtime, on the same computer at the same time.
To provide a code-execution environment that promotes safe execution of code, including code created by
an unknown or semi-trusted third party.
Supports Rapid Application Development (RAD).
Xamarin/Mono is a .NET implementation for running apps on all the major mobile operating systems,
including iOS and Android.
Architecture of .NET Framework
The Common Language Runtime
The two major components of .NET
Framework are the Common Language
Runtime and the .NET Framework Class
Library.
The Common Language Runtime (CLR) is the
execution engine that handles running
applications. It provides services like thread
management, garbage collection, type-
safety, exception handling, and more.
Common Type System (CTS) is a strict type-
and-code-verification infrastructure.
Programmers write apps in their development
language of choice yet take full advantage of
the runtime, the class library, and
components written in other languages by
other developers
Yotta B o t B u s i n e s s S o l u t i o n s 2
15
Ravi Consultant & Corporate Trainer +91 8310068586
Garbage collection
.NET's garbage collector manages the allocation and release of memory for your application. Each time you
create a new object, the common language runtime allocates memory for the object from the managed
heap. As long as address space is available in the managed heap, the runtime continues to allocate space
for new objects. However, memory is not infinite. Eventually the garbage collector must perform a
collection in order to free some memory. The garbage collector's optimizing engine determines the best
time to perform a collection, based upon the allocations being made. When the garbage collector performs
a collection, it checks for objects in the managed heap that are no longer being used by the application
and performs the necessary operations to reclaim their memory.
The garbage collector provides the following benefits:
Frees developers from having to manually release memory.
Allocates objects on the managed heap efficiently.
Reclaims objects that are no longer being used, clears their memory, and keeps the memory
available for future allocations.
Provides memory safety by making sure that an object cannot use for itself the memory allocated
for another object.
Fundamentals of memory
The following list summarizes important CLR memory concepts.
Each process has its own, separate virtual address space. All processes on the same computer
share the same physical memory and the page file, if there is one.
By default, on 32-bit computers, each process has a 2-GB user-mode virtual address space.
As an application developer, you work only with virtual address space and never manipulate
physical memory directly. The garbage collector allocates and frees virtual memory for you on the
managed heap.
If you're writing native code, you use Windows functions to work with the virtual address space. These
functions allocate and free virtual memory for you on native heaps.
When you initialize a new process, the runtime reserves a contiguous region of address space for the
process. This reserved address space is called the managed heap.
As long as address space is available, the garbage collector continues to allocate space for new objects in
this manner.
The garbage collector's optimizing engine determines the best time to perform a collection based on the
allocations being made. When the garbage collector performs a collection, it releases the memory for
objects that are no longer being used by the application.
Garbage collection occurs when one of the following conditions is true:
The system has low physical memory. This is detected by either the low memory notification from
the OS or low memory as indicated by the host.
The memory that's used by allocated objects on the managed heap surpasses an acceptable
threshold. This threshold is continuously adjusted as the process runs.
The GC.Collect method is called. In almost all cases, you don't have to call this method, because
the garbage collector runs continuously. This method is primarily used for unique situations and
testing.
To reserve memory, the garbage collector calls the Windows VirtualAlloc function and reserves one
segment of memory at a time for managed applications.
Yotta B o t B u s i n e s s S o l u t i o n s 3
15
Ravi Consultant & Corporate Trainer +91 8310068586
The garbage collector also reserves segments, as needed, and releases segments back to the operating
system (after clearing them of any objects) by calling the Windows VirtualFree function.
The heap is organized into generations so it can handle long-lived and short-lived objects.
Generation 0. This is the youngest generation and contains short-lived objects. An example of a short-lived
object is a temporary variable. Garbage collection occurs most frequently in this generation. Most objects
are reclaimed for garbage collection in generation 0 and do not survive to the next generation.
Generation 1. This generation contains short-lived objects and serves as a buffer between short-lived
objects and long-lived objects.
Generation 2. This generation contains long-lived objects. An example of a long-lived object is an object in
a server application that contains static data that's live for the duration of the process.
Collecting a generation means collecting objects in that generation and all its younger generations. A
generation 2 garbage collection is also known as a full garbage collection, because it reclaims objects in all
generations
The .NET garbage collector (GC) divides objects up into small and large objects.
SOH - Small object heap - object is less than 85,000 bytes
LOH - large objects - object is greater than or equal to 85,000 bytes in size
Large objects belong to generation 2 because they are collected only during a generation 2 collection.
https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals
https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/large-object-heap
Stack Heap
public void Method1()
{
i=4
// value type variables
int i = 4; y=2
int y = 2;
i=4
// Reference type cls1 (ref)
Class1 cls1 = new Class1();
cls1
} y=2 Object
i=4
cls1
Object
Yotta B o t B u s i n e s s S o l u t i o n s 4
15
Ravi Consultant & Corporate Trainer +91 8310068586
Class Library
The Class Library provides a set of APIs and types for common functionality. It provides types for strings,
dates, numbers, etc. The Class Library includes APIs for reading and writing files, connecting to databases,
drawing, and more. The class library is a comprehensive, object-oriented collection of reusable types that
you use to develop apps ranging from traditional command-line or graphical user interface (GUI) apps to
apps based on the latest innovations provided by ASP.NET, such as Web Forms and XML web services.
.NET Framework also includes an extensive library of over 4000 classes organized into namespaces that
provides a wide variety of useful functionality for everything from file input and output to string
manipulation to XML parsing, to Windows Forms controls.
When an app runs, the CLR takes the assembly and uses a just-in-time compiler (JIT) to turn it into machine
code that can execute on the specific architecture of the computer it is running on.
Managed code
is just that: code whose execution is managed by a runtime. Managed code is written in one of the high-
level languages that can be run on top of .NET, such as C#, Visual Basic, F# and others. When you compile
code written in those languages with their respective compiler, you don’t get machine code. You get
Intermediate Language code which the runtime then compiles and executes.
Intermediate Language code
You can write .NET apps in C#, F#, or Visual Basic
Byte Code
JIT
Native Code
Yotta B o t B u s i n e s s S o l u t i o n s 5
15
Ravi Consultant & Corporate Trainer +91 8310068586
Finding Framework Versions
Verify .Net framework version in your machine
1. Check the below path in your windows registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full
2. Using command prompt
C:\Users\Rskv>dir %windir%\Microsoft.NET\Framework /AD
Volume in drive C has no label.
Volume Serial Number is CCAA-82EC
Directory of C:\WINDOWS\Microsoft.NET\Framework
Yotta B o t B u s i n e s s S o l u t i o n s 6
15
Ravi Consultant & Corporate Trainer +91 8310068586
2019-11-15 08:13 <DIR> .
2019-11-15 08:13 <DIR> ..
2019-11-15 21:27 <DIR> v1.0.3705
2019-11-15 21:27 <DIR> v1.1.4322
2019-12-22 15:44 <DIR> v2.0.50727
2019-11-15 20:37 <DIR> v3.0
2019-11-15 20:37 <DIR> v3.5
2020-04-03 07:24 <DIR> v4.0.30319
0 File(s) 0 bytes
8 Dir(s) 14,408,458,240 bytes free
C:\Users\Rskv>
C:\Users\Rskv>cd %windir%\Microsoft.NET\Framework\v4.0.30319
C:\Windows\Microsoft.NET\Framework\v4.0.30319>
C:\Windows\Microsoft.NET\Framework\v4.0.30319>MSBuild.exe -version
Microsoft (R) Build Engine version 4.8.3752.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.
4.8.3752.0
C:\Windows\Microsoft.NET\Framework\v4.0.30319>
Verify .NET Core SDK version
C:\Users\Rskv>dotnet --list-sdks
2.1.801 [C:\Program Files\dotnet\sdk]
3.1.200 [C:\Program Files\dotnet\sdk]
The compiler determines a default based on these rules:
Target framework version C# language version default
.NET Core 3.x C# 8.0
.NET Core 2.x C# 7.3
C:\Users\Ravi>dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.412
Commit: 751fd182ef
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19043
OS Platform: Windows
RID: win10-x64
Yotta B o t B u s i n e s s S o l u t i o n s 7
15
Ravi Consultant & Corporate Trainer +91 8310068586
Base Path: C:\Program Files\dotnet\sdk\3.1.412\
Host (useful for support):
Version: 3.1.18
Commit: 5d3919d34e
.NET Core SDKs installed:
3.1.402 [C:\Program Files\dotnet\sdk]
3.1.412 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.18 [C:\Program
Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
C:\Users\Ravi>
Assembly
Assemblies form the fundamental units of deployment, version control, reuse, activation scoping, and
security permissions for .NET-based applications.
An assembly is a collection of types and resources that are built to work together and form a logical unit of
functionality.
Assemblies take the form of executable (.exe) or dynamic link library (.dll) files, and are the building blocks
of .NET applications.
Assemblies are only loaded into memory if they are required. If they aren't used, they aren't loaded. This
means that assemblies can be an efficient way to manage resources in larger projects.
The assembly manifest has metadata that is used for resolving types and satisfying resource requests. The
manifest specifies the types and resources to expose outside the assembly, and enumerates other
assemblies on which it depends. Microsoft intermediate language (MSIL) code in a portable executable (PE)
file won't be executed unless it has an associated assembly manifest.
You can use development tools, such as Visual Studio, that can create .dll or .exe files.
Also assemblies can be built using the command-line compilers with csc.exe.
Private Assembly and Shared Assembly
For libraries that target the .NET Framework, you can share assemblies between applications by putting
them in the global assembly cache (GAC). You must strong-name assemblies before you can include them
in the GAC.
Yotta B o t B u s i n e s s S o l u t i o n s 8
15
Ravi Consultant & Corporate Trainer +91 8310068586
Strong-named assemblies
Strong-naming an assembly creates a unique identity for the assembly, and can prevent assembly conflicts.
A strong named assembly is generated by using the private key that corresponds to the public key
distributed with the assembly, and the assembly itself. The assembly includes the assembly manifest, which
contains the names and hashes of all the files that make up the assembly.
You want to enable your assemblies to be referenced by strong-named assemblies.
An app needs access to different versions of the same assembly. This means you need different versions of
an assembly to load side by side in the same app domain without conflict.
You can strongly name an assembly using Visual Studio or by using sn.exe command line utility.
Create and sign an assembly with a strong name by using Visual Studio
In Solution Explorer, open the shortcut menu for the project, and then choose Properties.
Choose the Signing tab.
Select the Sign the assembly box.
In the Choose a strong name key file box, choose Browse, and then navigate to the key file. To create a new
key file, choose New and enter its name in the Create Strong Name Key dialog box.
Re-build the project. You get strongly named assembly.
Using Sn.exe (Strong Name tool)
First, create the key pair:
Yotta B o t B u s i n e s s S o l u t i o n s 9
15
Ravi Consultant & Corporate Trainer +91 8310068586
C:\>sn -k sgKey.snk
The following example signs the assembly MyAssembly.dll with a strong name by using the key file
sgKey.snk using the Assembly Linker tool;
C:\>al /out:MyAssembly.dll /keyfile:sgKey.snk
Global Assembly Cache
Each computer where the Common Language Runtime is installed has a machine-wide code cache called
the Global Assembly Cache. The Global Assembly Cache stores assemblies specifically designated to be
shared by several applications on the computer.
You should share assemblies by installing them into the Global Assembly Cache only when you need to. As
a general guideline, keep assembly dependencies private, and locate assemblies in the application directory
unless sharing an assembly is explicitly required.
Starting with the .NET Framework 4, the default location for the Global Assembly Cache is
%windir%\Microsoft.NET\assembly. In earlier versions of the .NET Framework, the default location is
%windir%\assembly.
C:\Windows\Microsoft.NET\assembly
Gacutil.exe
Run Developer command prompt for Visual Studio as Administrator and enter the below command with
your assembly with full path
gacutil -i D:\Ravi\.Net\training\CSharp\Utility\bin\Release\Utility.dll
To remove from GAC
gacutil –u Utility
C:\Windows\System32>gacutil -u Utility
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.0
Copyright (c) Microsoft Corporation. All rights reserved.
Assembly: Utility, Version=1.0.0.0, Culture=neutral, PublicKeyToken=85510391be85ce68,
processorArchitecture=MSIL
Uninstalled: Utility, Version=1.0.0.0, Culture=neutral, PublicKeyToken=85510391be85ce68,
processorArchitecture=MSIL
Assembly: Utility, Version=1.0.1.0, Culture=neutral, PublicKeyToken=85510391be85ce68,
processorArchitecture=MSIL
Uninstalled: Utility, Version=1.0.1.0, Culture=neutral, PublicKeyToken=85510391be85ce68,
processorArchitecture=MSIL
Yotta B o t B u s i n e s s S o l u t i o n s 10
15
Ravi Consultant & Corporate Trainer +91 8310068586
Number of assemblies uninstalled = 2
Number of failures = 0
C:\Windows\System32>
Full path of gacutil.exe file in windows 10
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\gacutil.exe"
IL Disassembler: Ildasm.exe
The IL Disassembler is a companion tool to the IL Assembler (Ilasm.exe). Ildasm.exe takes a portable
executable (PE) file that contains intermediate language (IL) code and creates a text file suitable as input to
Ilasm.exe.
.NET Framework Stack
CLR (Common Language Runtime) : It is a run-time environment which executes the code written in
any .NET programming language. .Net framework provides the support for many languages like C#,
F#, C++, Cobra, Jscript.Net, VB.Net, Oxygene etc
FCL (Framework Class Library) : A large number of class libraries are present in this framework
which is known as FCL.
Types of Applications : Mainly the applications which are built in .Net framework is divided into the
following three categories :
WinForms: Form – Based applications are considered under this category. In simple terms, we
can say client based applications which read and writes the file system comes under this
category.
ASP .NET: Web-Based applications come under this category. ASP.Net is a framework for web
and it provides the awesome integration of HTML, CSS and JavaScript which makes it useful to
develop the web applications, websites and web services. Web services were added in .Net
Framework 2.0 and considered as a part of ASP.NET web applications.
ADO .NET: It includes the application which are developed to communicate with the database
like MS SQL Server, Oracle etc. comes. It mainly consists of classes that can be used to connect,
retrieve, insert and delete data.
WPF (Windows Presentation Foundation) : Windows Presentation Foundation (WPF) is a
graphical subsystem given by Microsoft which uses DirectX and is used in Windows-based
applications for rendering UI (User Interface). WPF was initially released as part of .NET
Framework 3.0 in 2006 and previously known as “Avalon”.
WCF (Windows Communication Foundation) : It is a framework for building connected and
service-oriented applications used to transmit the data as asynchronous from one service
endpoint to another service point. It was previously known as the Indigo.
WF (Windows Workflow Foundation) : It is a technology given by Microsoft which provides a
platform for building workflows within .Net applications.
Yotta B o t B u s i n e s s S o l u t i o n s 11
15
Ravi Consultant & Corporate Trainer +91 8310068586
Card Space: It is a Microsoft .NET Framework software client which is designed to let users
provide their digital identity to online services in a secure, simple and trusted way.
LINQ (Language Integrated Query) : It is introduced in .Net framework version 3.5. Basically, it is a
query language used to make the query for data sources with VB or C# programming languages.
Entity Framework: It is open–source ORM (Object Relational Mapping) based framework which
comes into .Net Framework version 3.5. It enables the .Net developer to work with database using
.Net objects. Before entity framework, .Net developers have performed a lot of things related
database. Like to open a connection to the database, developers have to create a Data Set to fetch
or submit the data to the database, convert data from the Data Set to .NET objects or vice-versa. It
creates the difficulties for developers and also it was the error-prone process, then “Entity
Framework” comes to automate all these database related activities for the application. So, Entity
Framework allows the developers to work at a higher level of abstraction.
REST (Representational State Transfer) and AJAX was added in .Net Framework 3.5 as an extension
and services of ASP.NET for enhancing web services of .NET Framework.
Parallel LINQ (Language Integrated Query): It comes in .Net Framework version 4.0 and also termed
as PLINQ. It provides a concurrent query execution engine for LINQ. It executes the LINQ in parallel
such that it tries to use as much processing power system on which it is executing.
TPL (Task Parallel Library): It is a set of public types and APIs. It allows the developers to be more
productive by simplifying the process of adding concurrency and parallelism to .Net applications.
.NET API For Store/UWP Apps: In 2012, Microsoft added some APIs for creating UWP(Universal
Windows Platform) apps for Windows using C# or VB. UWP is one choice for creating apps that run
on Windows 10 devices, and can be combined with other platforms. UWP apps can make use of
Win32 APIs and .NET classes
Task-Based Asynchronous Model: It is model used to describe the asynchronous operations and
tasks in .Net Framework.
Visual Studio
The Visual Studio integrated development environment is a creative launching pad that you can use to edit,
debug, and build code, and then publish an app. An integrated development environment (IDE) is a feature-
rich program that can be used for many aspects of software development. Over and above the standard
editor and debugger that most IDEs provide, Visual Studio includes compilers, code completion tools,
graphical designers, and many more features to ease the software development process.
Yotta B o t B u s i n e s s S o l u t i o n s 12
15
Ravi Consultant & Corporate Trainer +91 8310068586
Solution and Projects
A solution is a container for one or more related projects, along with build information, Visual Studio
window settings, and any miscellaneous files that aren't associated with a particular project. A solution is
described by a text file (extension .sln) with its own unique format; it's not intended to be edited by hand.
When you create an app or website in Visual Studio, you start with a project. In a logical sense, a project
contains all files that are compiled into an executable, library, or website. Those files can include source
code, icons, images, data files, and so on. A project also contains compiler settings and other configuration
files that might be needed by various services or components that your program communicates with.
Visual Studio uses MSBuild to build each project in a solution, and each project contains an MSBuild project
file. The file extension reflects the type of project, for example, a C# project (.csproj), a Visual Basic project
(.vbproj), or a database project (.dbproj). The project file is an XML document that contains all the
information and instructions that MSBuild needs in order to build your project, including the content,
platform requirements, versioning information, web server or database server settings, and the tasks to
perform.
In the below example, the solution ‘Philips’ has 3 projects. Electronics and RandD are console application
projects and Utility project is of type Library.
When you build the solution, console applications built into exe (executable) files, and library projects are
built into dll (dynamic link library) files.
Yotta B o t B u s i n e s s S o l u t i o n s 13
15
Ravi Consultant & Corporate Trainer +91 8310068586
Yotta B o t B u s i n e s s S o l u t i o n s 14
15
Ravi Consultant & Corporate Trainer +91 8310068586
Yotta B o t B u s i n e s s S o l u t i o n s 15
15
Ravi Consultant & Corporate Trainer +91 8310068586