Understanding OverloadResolutionPriority attribute in C# 13

 
 
  • Gérald Barré
C# 13 adds support for a new attribute: [OverloadResolutionPriority]. This attribute is niche, so most of you won't use it. However, it's a nice addition to the language, and it's worth knowing about it if you are writing libraries. Let's consider this simple example: Sample.Test(); // Print: Test 1 static class Sample { public static void Test() => Console.WriteLine("Test 1"); } Now, you want to update… [read more]

Disabling HSTS for localhost using a browser extension

 
 
  • Gérald Barré
 
Http Strict Transport Security (HSTS) is a security mechanism that instructs the browser to automatically redirect http requests to https before sending a request to the server. When you are developing a web application, you should disable HSTS for localhost. This is because enabling HSTS on localhost has implications for other applications. For instance, some applications start a local web server and… [read more]

Using Mutex<T> to synchronize access to a shared resource

 
 
  • Gérald Barré
When you need to access a shared resource, you can use the lock statement or a synchronization primitive such as a Mutex to synchronize access to the resource. However, it's easy to forget it in complex code. When you need to synchronize access to a single resource, you can use a var obj = new object(); var value = 42; lock (obj) { // You need to ensure you use lock everywhere you access the shared… [read more]

Waiting for a ManualResetEventSlim to be set asynchronously

 
 
  • Gérald Barré
ManualResetEventSlim represents a thread synchronization event that, when signaled, must be reset manually. This is a common synchronization primitive. However, it doesn't expose a method to wait asynchronously. Hopefully, it's not too complicated to create an extension method using ThreadPool.RegisterWaitForSingleObject and TaskCompletionSource. static class Extensions { public static Task WaitAsync(this… [read more]

How to export user aliases from Microsoft Entra using PowerShell

 
 
  • Gérald Barré
Microsoft Graph is a REST API that allows you to interact with Microsoft 365 services. You can use it to automate tasks such as creating users, updating their properties, or exporting data. In this post, I'll show you how to export user email addresses and aliases from Microsoft Entra using PowerShell. First, you need to install the Microsoft.Graph module: Install-Module Microsoft.Graph -Scope CurrentUser… [read more]

Useful resources to write Roslyn Analyzers

 
 
  • Gérald Barré
Roslyn analyzers and source generators are useful but it's not easy to start writing them. The documentation is not at the same level as .NET or ASP.NET Core. There are some good resources on the internet. In this post, I share some resources to help you write Roslyn analyzers and source generators. View Syntax tree and IOperation tree When you write a Roslyn analyzer, you need to understand the syntax… [read more]