Application models
An
application model consists of the components that are specific to
type of app:
- WPF (Windows Presentation Foundation)
- WinForms (Windows Forms)
- ASP.NET
- ASP.NET Core (Which is the successor and reimplementation of ASP.NET)
- UWP
- PowerShell (cmdLets)
- Console
- Xamarin Forms
Linq,
ADO.NET, Serializtion are components that are not constrained to a specific type of app and are therefore not consideree to be application models.
Windows Presentation Foundation (WPF)
WPF is a framework for UI creation, primarily intended for desktop client applications on Windows OS.
WPF uses Extensible Application Markup Language (XAML).
Two important concepts related to concurrency:
- Dispatcher
- Thread affinity
Because the designers of WPF assumed that developers wanted a flexible and extensible layout model which can be driven declarativly, rather than imperatively, a primary architectural decision for the WPF was to proritize properties over methods or events, thus achieving a declarative programming model.
The declarative programming model gives raise to XAML.
P:\ath\to\dir> dotnet new wpf
P:\ath\to\dir> dotnet run
WPF paints from the back to front, allowing to over-paint already painted regions (aka painter's algorithm).
Events are said to bubble from a target UI element to the root and to tunnel in the opposite direction. They tunnel for event-previewing and bubble to activate the actual event.
WPF Build Engine
Step | Actions |
Pre-build initialization | Determines the location of tools and libraries |
Resolving References (ResolveAssemblyReference ) | |
Markup Compilation, Pass 1 | parse and compile XAML files, results (1: compiled and 2: CodeDOM representation) stored in obj\Release folder. Also create page….g.cs for each page (g = generated). Microsoft.Build.Tasks.Windows.MarkupCompilePass1 ) |
Markup Compilation, Pass 2 | |
File classification | |
Core Compilation | compilation of source code |
Manifest generation | |
XAML
XAML is the markup language for WPF. It has the declarative programming model in mind.
Windows Forms
A GUI class library with the .NET Framework.
Windows Forms is primarily targeted for desktop applications.
ASP.NET
Used to develop web applications.
ASP.NET has access to the CLR, so ASP.NET programs can be written in different .NET languages.
ASP.NET Core
ASP.NET Core is a re-implementation of ASP.NET. It runs on multiple platforms (OS X,
Windows,
Linux).
TODO
.NET Framework Class Library (FCL)
The .NET Framework Class Library (FCL) is organized into a hierarchy of namespaces. Two common namespaces are System.*
and Microsoft.*
.
The FCL is comparable in scope with the standard libraries of
Java.
FCL implements the CLI Base Class Library (BCL) and other class libraries.
FCL consists of the following libraries:
- BCL
- Windows Forms
- ASP.NET
- Windows Presentation Foundation (WPF)
Base Class Library (BCL)
The BCL provides basic features such as namespaces and classes.
BCL is the core of FCL.
Common Type System
The Common Type System (CTS) defines how data types (that are shared by CTS-compliant languages) are declared, used and manged in the runtime.
These data types consist of
- value types, and
- reference types
CLS is a subset of the CTS. This means that all of the rules in the CTS also apply to the CLS, unless the CLS rules are more strict.
.NET Framework
The .NET Framework only runs on
Windows based devices.
The .NET Framework is constitued by a combination of BCL and FCL.
The last major version of .NET Framework is 4.8. It is included in the
Windows 10 May 2019 Update
.NET Core
.NET Core is a
open source re-implementation of .NET Framework that runs on multiple platforms (not only Windows).
Multiple .NET Core versions can be installed on the same computer (referred to as side-by-side).
.NET Core was introduced in November 2014 and released in 2016.
.NET Core 3.0 was released in September 2019.
Microsoft thinks that new .NET applications should be based on .NET Core.
Common Language Runtime (CLR)
A CLR converts
managed code (intermediate language) into
machine code and then executes it (
IL to native translation).
These features make .NET programs managed.
A managed type that acceses unmanaged resources typically implements the
System.IDisposable
interface.
.NET Framework | Common Language Runtime (CLR) |
.NET Core | Core Common Language Runtime (CoreCLR) |
UWP | .NET Native, a Ahead of Time compiler. |
? | Mono runtime |
.NET Core uses CoreCLR.
CLR implements the VES.
The base class for all components in the common language runtime is System.ComponentModel.Component
(which derives from System.ComponentModel.IComponent
).
A file without an assembly manifest cannot be loaded by the .NET Framework. common language runtime. (See csc.exe -target:module
)
PS C:\> [Runtime.InteropServices.RuntimeEnvironment]::SystemConfigurationFile #
PS C:\> [Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory() # Directory where the CLR is installed.
PS C:\> [Runtime.InteropServices.RuntimeEnvironment]::GetSystemVersion() # Version number of CLR that is is running the current process.
CoreCLR
CoreCLR is the runtime used as part of .NET core.
Originally, CoreCLR was the runtime of Silverlight.
CoreRT
CoreRT is neither a virtual machine nor does it have a JIT. It has a garbage collector, though.
Common Language Infrastructure (CLI)
CLI defines how program code can be translated into CIL.
The CLI is a specification that defines
- CTS
- Metadata (Which can be read with reflection)
- Common Language Specification (CLS)
- Virtual Execution System (VES)
The VES loads and executes CLI-compatible programs, using the metadata to combine separately generated pieces of code at runtime.
The *.NET Framework* is Microsoft's original
implementation of the CLI.
Specification (?) | .NET Framework implementation |
Virtual Execution System (VES) | Common Language Runtime |
Standard Libraries | Framework Class Library |
Common Language Specification (CLS)
The CLS specifies the features that a language must support that targets .NET (framework?).
In order to be CLS compliant, only those features that are common to all .NET languages must be exposed to potential users.
A CLS compliant .NET component (assembly?, dll?) ensures that it can be accessed from any other .NET language.
CLS compliance is primarily of concern to library developers who want to ensure that their libraries are accessible in any language that targets the .NET Framework.
Virtual Execution System (VES)
The VES loads and runs CLI compliant programs and enforces the CTS model.
Languages
If a
language is CLI compliant, it can use .NET.
Some languages are
- C#
- F#
- Visual Basic
- C++/CLI
- IronPython
- Oxygene
- Phalanger
- …
Managed code
Managed code is called managed because its execution is managed by a runtime (CLR).
Managed code is written in .NET languages such as
- C#
- F#
- Visual Basic
- etc. …
The respective compilers then produce intermediate language (IL).
An instance of the System.AppDomainManager
class represents the equivalent of an unmanaged host. It prepares an AppDomain before managed code runs.
Compiling code
A .NET compiler translates source code, written for example in
C# to intermediate language (IL) and metadata.
The metadata describes the types that were compiled, including its members and methods. The metadata can then be read through reflection and consequently, Type Libraries and Interface Definition Language is obsoleted.
(Common) Intermediate language (IL, CIL)
Intermediate language is the product of a high-level .NET language compiler. It consists of the instruction set that is understood by the VES.
The intermediate language is also referred to as Common Intermediate Language (CIL).
CIL was formerly called Microsoft intermediate language (MSIL).
CIL is abstracted from the hardware. It defines a (CPU and platform-independent, stack based, object-oriented) binary instruction set within the Common Language Infrastructure (CLI) specification. CIL can be efficiently translated to native code.
CIL code is taken by a CLR which then Just-in-Time compiles it (aka JIT-ing). The product of JIT-ing is machine code that can be executed on a CPU.
When CIL is executed, the (platform-specific) VES compiles the CIL to machine language (just-in-time compilation).
It is also possible to use ahead-of-time compilation (
ngen.exe
).
With
ngen.exe
, an entire
assembly is compiled, rather than one method as they're being used and a persisted native image is stored in a file on disk.
Roslyn is the code name for a *.NET compiler platform* that features a compiler for C# and Visual Basic .NET. These compilers create CIL from the respective source files.
RyuJIT compiles CIL into byte code.
.NET implementations
.NET Framework | The original framework, first released in 2002. Won't probably have a version 5.0 |
.NET Core | Re-implementation of .NET Framework. .NET Framework will be merged into .NET Core |
Xamarin(?) / Mono(?) | Xamarin was started independently from Microsoft. Microsoft bought Xamarin in 2016. |
Universal Windows Platform (UWP) | |
.NET Standard
.NET Standard is a library that combines the APIs of .NET Framework, .NET Core and Xamarin.
.NET Standard was introduced by Microsoft in 2016.
Roslyn
Microsoft's latest C# compiler ecosystem.
Roslyn is not included with .NET Framework; it still has the traditional csc.exe
and vbc.exe
.
Mono
Mono started as an open source alternative to .NET Framework and is the original cross-platform implementation of .NET
Mono is typically run with a Just-in-Time compiler but also has a ahead-of-time compiler (static compilation).
Mono is the runtime used as part of Xamarin.
P/Invoke
P/Invoke (Platform Invocation Services) is a feature of CLI implementations that allows
managed code to call unmanaged (aka native) code and use features such as structs or callbacks.
P/Invoke seems to be .NET's equivalent for Java Native Interface.
JIT
The Just-in-time compiler translates IL to machine code that runs on a CPU. Thus, it is similar to a AOT (Ahead-of-Time) compiler. However, the JIT translates code when needed and on the same machine that the machine code eventually runs.
When JIT translates IL, it also checks if the code is type safe. Code that is not type safe is only allowed to be executed if it originates from the computer where it should be executed.
Tools
Some tools that run on all
.NET implementations are
- MSBuild
- NuGet (package manager)
- CAKE, FAKE (Open source orchestration tools)
- Project system (based on .csproj, .vbproj or .fsproj files)
- .NET language compilers
.NET Native
A (Ahead-of-Time) compiler (that produces machine code) on the developer's machine.
UWP was the first application framework that was supported by .NET Native.
NGEN
NGEN = Native image GENeration.
NGEN compiles code typically at installation time.
Namespaces
Parts of namespace names are delimited by a dot (.
).
The using
directive removes the necessity to specify the full namespace for every class.
The root namespace is referred to with global
(for exampleglobal::System
).
Common Type System CTS
The Common Type System (CTS) is a standard (ECMA 335, Common Language Infrastructure (CLI), Partitions I to VI) that specifies how type definitions and specific values of types are represented in computer memory.
This standard allows (even different) .NET languages to share data and objects.
A type is either
- a value type
- a reference type (similar to pointers)
Common types
- Classes
- Structures
- Enumerations
- Interfaces
- Delegates