Code Maze Author

Code Maze

This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.
Also find me here:



MY ARTICLES:

Difference Between String, FormattableString, IFormattable in C#

C# provides different ways of manipulating strings, which can be helpful when designing and implementing systems. So, in this article, we will delve deep into the distinctions among String, FormattableString, and IFormattable in C#. Besides that, we will test whether...

Task.FromResult vs Task.CompletedTask vs Return in C# Async Methods

Task.CompletedTask, Task.FromResult() and a plain return all answer one question: how does a method hand back a Task when there is nothing to wait for? Return Task.CompletedTask when the method's return type is Task and the work is already done. Return...

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...

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)....

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...

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...

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...

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 Programatically

.NET Framework allows us to create applications for various platforms and devices. With each new version, .NET introduces new features and fixes, while rarely including changes that could cause compatibility issues. Therefore, upgrading a .NET project to a newer...

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"...

Refactoring Couplers in C#

In this article, we will learn about couplers, their impact, and how to find and fix them. Couplers establish dependencies between components, making our code challenging to understand, modify, and test. The knowledge about how to untangle our code can certainly help...