Dynamically Switching DbContext at Runtime Using Entity Framework Core
In this article, we will discuss why having multiple databases behind an application is useful and how dynamically switching an EF DbContext can be achieved without experiencing downtime. Feel free to check out our series of articles on Entity Framework Core. [sc...
How to Get a JSON Array Using IConfiguration in ASP.NET Core
In this article, we will explore how to get a JSON array using IConfiguration. In modern web applications, JSON is a widely used data interchange format due to its lightweight nature and ease of use. When developing an ASP.NET Core application, it is common to store...
Deploy ASP.NET Core Applications on Linux With Apache
In this article, we are going to learn how to deploy ASP.NET Core applications to an Ubuntu Linux server with Apache. Â Let's get...
Adding Header and Footer to a PDF Using the iText Library in C#/.NET
In this article, we will continue our journey using the iText library to create PDF documents. In our previous article, 'Introduction to PDF Manipulation With iText (Formerly iTextSharp)'Â we discussed the basics of the iText7 library. We talked about licensing and the...
C# Readonly Modifier: Fields, Structs and Properties
The readonly modifier in C# stops a field from being assigned once its object is built. We can set a readonly field in its declaration, in a constructor or in an init accessor, and the compiler rejects every other assignment. It also works on structs and on struct...
How to Use Mutex in C#
In this article, we are going to learn how to use the Mutex class in C#. Multithreading can significantly boost an application's performance, but it also brings challenges related to synchronizing and coordinating tasks across different threads (and even processes)....
Efficiently Converting Strings With UTF-8 String Literals in C#
In this article, we'll learn about the new syntax for UTF-8 string literals in C# 11, highlighting the performance enhancements vs. the older API. ...
How to Mark Methods as Deprecated in C# (Obsolete Attribute)
To mark a method as deprecated in C#, we put the [Obsolete] attribute above it. Every call to that method then gets a compiler warning, and with true as the second argument, the call stops compiling. A message tells callers what to use instead, and since .NET 5 we can...
How to Conditionally Resolve Dependencies in .NET
In this article, we will learn how to conditionally resolve dependencies in .NET. Conditional dependency resolution is a...
Implement API Key Authentication in ASP.NET Core
Many developers widely use API key authentication to secure API endpoints. This approach necessitates clients to provide a valid API key for accessing the endpoints. When implementing API key authentication in ASP.NET Core, it's crucial to understand how to pass the...
How to Mock IOptions in ASP.NET Core
In this article, we'll unveil a straightforward approach to mock IOptions<T>, ensuring our tests remain both thorough and independent of real-world configurations. [sc name="github"...
Fix HTTP Error 500.31 – Failed to Load ASP.NET Core Runtime
HTTP Error 500.31 means IIS could not start the .NET runtime our ASP.NET Core app targets. Usually that runtime isn't installed on the server, and we fix it by installing the matching .NET Hosting Bundle and restarting IIS. A misspelled DLL name in web.config produces...
Targeting Multiple Frameworks in a .NET Project
In this article, we're going to explain the importance and benefits of targeting multiple frameworks in a single .NET project. Let's start....
Prevent SQL Injection With EF Core, Dapper, and ADO.NET
SQL Injection is a severe security vulnerability that can harm applications that use databases. In this article, we'll learn about SQL Injection attacks, what they can do, and how to protect our applications from them. We'll focus on using popular ORM tools like EF...
How to Generate a Stream From a String?
Generating a stream from a string is a common operation we perform when building applications. In this article, we will discuss two ways we can achieve that in .NET. [sc name="github"...
Differences Between Const and Readonly in C#
In this article, we will discuss the differences between const and readonly keywords in C#. const and readonly allow us to declare immutable values in C#. [sc name="github"...
How to Determine .NET Version Programmatically in C#
To get the .NET version from C# code, we read Environment.Version for the runtime version number, or RuntimeInformation.FrameworkDescription for a readable name such as .NET 10.0.10. Both describe the runtime our app is running on right now, which can be newer than...
Differences Between Equality Operator (==) And Equals Method In C#
In this article, we delve into the similarities and differences between the equality (==) operator and the Equals method in C#. [sc name="github"...
Primary Constructors for Classes and Structs in C#
In this article, we'll take a look at a new feature of C# 12 and .NET 8 for classes and structs called primary constructors that is still in preview at the time of writing the article. [sc name="github"...
Serilog Rolling File Logging: Intervals and Retention
Pass rollingInterval to the file sink and Serilog starts a new file on that schedule: .WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day) produces log20260824.txt, log20260825.txt, and so on. Two more options decide how long that stays manageable....










