Ei Exe or Dll file (Native Code) Run

Ei Nay Chi Zaw (HND – 18) Task 3 Programming in .

Net Assignment 2  Table of ContentsTask 3. 1CLR (Common language runtime) 1FCL (Framework Class Library) 5Reference list 8 Task 3                Theprogramming languages have to use the .NET framework’s features in executingthe output. .NET is composed of two main components.1)   CLR – Common Language Runtime2)   FCL – Framework Class Library CLR (Common language runtime)       What is CLR (Common language runtime)?          CLR is therun-time environment that providing the development to be easier by running thecodes, compiling the codes, and checking the errors of the codes. The codesthat run with CLR are called the managedcodes. And the CLR provides codecompilation, memory management, exception handling, type safety, garbagecollection, and thread management.

Best services for writing your paper according to Trustpilot

Premium Partner
From $18.00 per page
4,8 / 5
Writers Experience
Recommended Service
From $13.90 per page
4,6 / 5
Writers Experience
From $20.00 per page
4,5 / 5
Writers Experience
* All Partners were chosen among 50+ writing services by our Customer Satisfaction Team

The CLR works as a layer between the Operating System and the program writtenin the .Net. And the main functionof the CLR is to convert the managed codes into executable programs. Theversions of .Net Framework, CLR and visual studio .

Net Framework Version CLR Version Visual Studio Versions 1.0 1.0 Visual Studio .

NET 1.1 1.1 2003 2.0 2.0 2005 3.0 2.

0 2005 3.5 2.0 2008 4 4 2010 4.5 4 2012 4.5.1 4 2013 4.5.2 4 2013 4.

6 4 2015 4.6.1 4 2015 4.6.2 4 2015 4.7 4 2015  How does CLR works?Compiling            LanguageCompilers (CIL) will convert the Code to Microsoft IntermediateLanguage (MSIL).

MSIL includes instructions for loading,storing, initializing and calling methods on objects. The MSIL are compiled into the portable executable (PE). The PEincludes Metadata which has theinformation about the PE like the version, languages, other data that theruntime uses at the execution time, and what class library will be needed bythe program. And CLR uses the metadata for many purposes.

The CLR uses themetadata to load and to locate the classes, place layouts in the memory,generate native code, and to make security. The metadata is used by JIT (Just-in-time) compilers to turninto executable codes. The executing result may be dll or exe file. Executing            When the method is called for the first time, themethod’s MSIL has been generated and has JIT compiled into native code. Andinstead of compiling all the codes in the assembly again, the native code isstored in the memory. And if the method is run for the second time, the storednative code is run instead of generating the MSIL again.

Here is an illustration of the CLR process. MSIL Source Code (C#, F#, Etc.)                                 Language compiler                                                                                                                                                         JITCompiler (inside CLR) Output Exe or Dll file (Native Code)                                                                                                                       Run on OS                                                                              Components of CLRMemory Management (garbage collection)          Memory management is one of the automatic service that theCLR provides during the managedexecution.

The memory is allocated by the CLR each time the developercreates a new object. And it provides garbagecollecting (GC) – returning the no longer needed memory to the computer. Thismeans that the developers don’t need to write codes for managing the memory.And the automatic memory management can solve many problems. Some are memoryleaking – forgot to return the memory, and trying to access the memory thatthat already cleared.           The garbagecollector (GC) decides itself when to make a collection based on theallocations. When the garbage collection performs a collection, itautomatically detects the objects that are no longer needed and performoperations to recover the memory.

The GC finds the no longer used objects byexamining the roots of the applications. By the way, every application hasroots which includes the static fields, parameters and variables. GC accesses the roots of the JIT-compilerand makes a graph out of it. And by looking at the object life time in thegraph, it can eliminate the objects that are no longer used.

Code compilation             TheC# program is loaded by the compiler and the compilation is started. The compilation compiles the source code into module. The module is used to producethe assembly which contains the MSIL codes. And then the CLR takes the assemblywhich contains the MSIL. The MSIL must be compiled to native code. There aretwo ways to compile.1)   .

Net FrameworkJIT (Just-in-time) compiler and 2)   .Net FrameworkNgen.exe (Native Image Generator)Thegreat thing of JIT is that it converts the MSIL as less as needed during theexecution and stores the rest of the native code in memory instead of takingtime and memory to convert all the MSIL codes. The JIT-compiler takes the MSIL to compile into a native code. The nativecode is stored in a heap. The native code compiled by the JIT compiler goes tothe OS Service and executed by themto output in the GUI. Thebad thing is that the code generated by the JIT compiler cannot be sharedacross multiple processes. To allow thegenerated code to be shared across multiple processes, the common languageruntime supports the Ngen.

exe to convert the MSIL into the native code justthe way like JIT compiler. But it has a little difference. 1)   It compiles all the MSIL codes at only one time.2)   The compilation is done before running the program.Exception handling            The errors can happen while running the codes orwriting the codes. These errors can be passed back to the codes and unexpectederrors can happen. So, the exceptionscan be provided to your codes to detect those errors before they become bigerrors.

Exceptions allow you to build applications that make a callto another function and then catch errors if they occur and handle them in thecalled application. However, exceptionhandling are not the same from one programming language to another. And theCommon Language Runtime solves this problem for all applications.             SystemException is used for theexceptions that are generated by the CLR.And the ApplicationException is the class for exceptions that are thrown asapplication.

And the user can createtheir own exceptions and extract from the ApplicationException class.            There are benefits of using themanaged Exception handling.1)   The exceptionscan be thrown and caught in the both managed and unmanaged code and itallows the user to use the exceptions outside of the environment he/she isworking in.

2)   The exceptions can be handled without the need for the same languageof the code that the exception is handling.3)   Exceptionsin CLR doesn’t require special syntax.4)   Exception handling in CLR is faster than the C++error handling.        FCL (Framework ClassLibrary)What is FCL?                                             FCL is thelibrary of the .NET Framework and contains classes, interfaces that arereusable. FCL is where the .NET framework’s application, components are made. Framework class library containsthousands of classes used to build different types of applications and providesall the basic functionalities and services that application needs.

  And the BCL (Base Class Library) providesthe most fundamental functionality of the FCL, such as System, System.Data, System.IO,   System.Resources, System.Text and etc.          FCL has manycross-language technologies, and these includes file I/O, text management, .

NETframework security checking, providing data access and encapsulating the datastructures. It includes set of libraries, including Windows Forms, ADO.NET,ASP.

NET, Language Integrated Query, Windows Presentation Foundation, andWindows Communication Foundation. And FCL includes a lot of classes andservices to support many applications such as 1)   Mobile application2)   Windows application3)   Web application (ASP.net , WCF)4)   Desktop application Functions of FCLClasses           The FCLincludes the classes that support the functions as shown. 1)   They can support for exception handlings.

2)   They can communicate with the underlying system.3)   They have ability to create web-client and alsoserver applications. 4)   They can connect with the databases and canaccess data from them. 5)   They can build Window-based GUI applications.6)   They can support for creating web services.What is BCL?            The long term for BCL is base class library. It contains the classes that can be used in allwindows, web or mobile applications.

The System namespace is the main ofthe BCL and it contains the classes, interfaces and attributes that the otherparts depends on. BCL has all the commonused classes of the application such as web, mobile and windows. It is thesubset of the FCL.

Example: themethod Console.WriteLine () is not usable in all applications since the WriteLine() belongs to the Console Application. So, it is not in the BCL (Base ClassLibrary).System Namespacehierarchy             .NET framework uses a dot syntaxnaming scheme that makes a hierarchy.And this technique sorts the relatedtypes into namespaces so they can be easy to search and use.

 Just like a folder can contain otherfolders and documents, a namespace can contain other namespaces or classes.           All thenamespaces are stems from the common root called the System namespace. This namespace includes the classes thatrepresent the base data types that are used by all applications such as Object,Array, Char, String, etc.

And from theSystem namespace, all other namespaces can be rooted from it. The firstpart of the name before the dot (.) is the namespace name. And the last part ofthe name is the type.

For example:System.Collections.Arraylist represents that the System.Collections is the namespace name and Arraylist is thetype that belongs to the System.Collections namespace.           The Framework class library can be extendedbut the System namespace will contain the classes that are useful for allapplications. Main namespaces inthe .NET Class library Namespace Description System This contains the classes that defines that common values, reference data types, events, event handlers, interfaces, math, and garbage collection and application environment.

System.IO This provides to support read and write data streams and files. And contains classes like FileStream, and Directory. System.Collections This contains classes that defines objects such as arrays, and lists.

System.Data It contains the classes that can implement child namespaces such as SqlClient which can be used to access the databases. System.XML This supports for processing the XML documents.

And this includes child namespaces such as Schema. System.Windows It contains the types that are used in Windows presentation Foundation (WPF) applications like animation clients, user interface controls and data binding.

System.Windows.Forms This contains classes that are used to create the windows applications.

System.Drawing Use for access to the graphic functionality of GDI. And contains the child namespaces such as Design, and Text. System.Security This contains the classes that presents the .NET framework security and permissions. System.Web.

Services This enables the users to build and use the web services. And contains such namespaces like Description, Discovery and Protocols. System.Web.Mobile This enables the users to build ASP.NET mobile web applications.

System.Net This provides simple programming interface for number of networking protocols.  What is WCF (WindowsCommunication Foundation)?             The windows communication foundationis the framework for sending messages over service endpoints. The endpoint canbe the client of services that make request data from another end point.

Andthe message can be a simple XML word. So they have to use the System.Xml. Beloware some classes. Class name Description XmlDictionary To implement a dictionary to optimize the WCF’s XML reader and writer.

XmlDictionaryReader To implement a dictionary to optimize the WCF’s XML reader. XmlDictionaryWriter To implement a dictionary to optimize the WCF’s XML writer.  What is WPF (Windowspresentation foundation)?            The wpf (Windows presentationfoundation) is for rendering the user interfaces in the windows basedapplications. It is also based on the XML derivative making it easier to changethe UI and forcing the separation of UI and the core code.          With WPF,developers can use the XAML (Extensible application markup language) to createthe custom controls, 3d graphics and animations. Silverlight             Silverlight is an applicationfrom Microsoft that can add 3D effects and cool designs to the web, mobile andwindows application.

And they can developed by .Net Framework. TheSystem.

Drawing can be used to develop the effects with Silverlight and childnamespaces of System.Windows can be used too.