IConfiguration vs IOptions NET
Synchronous and Asynchronous in .NET Core
Model Binding and Validation in ASP.NET Core
ControllerBase vs Controller in ASP.NET Core
ConfigureServices and Configure methods
IHostedService interface in .NET Core
ASP.NET Core request processing
| OWASP Top 10 | NET-Core-Runtime-Internals | |
CLR, CTS,CLS, BCL, and SDK Components in .NET core |
The Common Language Runtime (CLR) is the virtual machine component of .NET Core that manages the execution of .NET programs. It provides services like memory management, security, exception handling, and Just-In-Time (JIT) compilation.
using System;
class Program {
static void Main() {
try {
string name = null;
Console.WriteLine(name.Length); // Throws NullReferenceException
} catch (Exception ex) {
Console.WriteLine("CLR Caught Error: " + ex.Message);
}
}
}
CLR is the backbone of .NET Core applications. It ensures safe, efficient, and cross-platform execution of code, making development faster and more reliable.
The Base Class Library (BCL) is a core set of libraries in .NET Core that provides fundamental building blocks for applications. It includes types for collections, file I/O, data types, threading, and more.
String, Int32, DateTimeList<T>
using System;
using System.IO;
using System.Collections.Generic;
class Program {
static void Main() {
// Write to a file
File.WriteAllText("data.txt", "Hello BCL!");
// Read from the file
string content = File.ReadAllText("data.txt");
Console.WriteLine("File Content: " + content);
// Use a generic list
List<int> numbers = new List<int> { 1, 2, 3 };
numbers.ForEach(n => Console.WriteLine("Number: " + n));
}
}
try-catch blocks around BCL operations.The BCL is the foundation of .NET Core development. It simplifies common programming tasks and ensures consistency, reliability, and performance across applications.
The .NET Core SDK (Software Development Kit) is a set of tools and libraries used to develop .NET Core applications. It includes compilers, the CLI (Command Line Interface), runtime, and the Base Class Library (BCL).
// Command to create a new console app dotnet new console -n HelloWorldApp // Navigate to the app folder cd HelloWorldApp // Run the app dotnet run
The .NET Core SDK provides a powerful and flexible foundation for building modern applications. By following best practices and leveraging its components, developers can create efficient, scalable, and maintainable software.
The Common Type System (CTS) defines how data types are declared, used, and managed in the .NET runtime. It ensures that all .NET languages can understand and work with each other's types.
// C# code int number = 100; // CTS type: System.Int32 // VB.NET equivalent ' Dim number As Integer = 100 ' Also CTS type: System.Int32
int, string, bool, etc.The Common Language Specification (CLS) is a set of rules that .NET languages must follow to ensure interoperability. Itβs a subset of CTS and focuses on features that are common across all .NET languages.
// CLS-compliant
public class Sample {
public int Age; // OK
}
// Not CLS-compliant
public class Sample {
public uint Age; // Not CLS-compliant (unsigned types not supported in all .NET languages)
}
[CLSCompliant(true)] to enforce CLS rules.uint, sbyte, or language-specific features.| Feature | CTS | CLS |
|---|---|---|
| Scope | Broad (all .NET types) | Narrow (subset of CTS) |
| Purpose | Type safety and runtime consistency | Language interoperability |
| Compliance | All .NET types must follow CTS | Public APIs should follow CLS |
CTS and CLS are foundational to .NETβs language interoperability. CTS ensures consistent type behavior across the runtime, while CLS ensures that code written in one language can be used by others. Together, they make .NET a powerful and flexible multi-language platform.
| OWASP Top 10 | NET-Core-Runtime-Internals | |