Different ways to check if a value is null in C#

  • Gérald Barré
In .NET there are multiple ways to check if a value is null. But all of them are not equivalent. Let's look at the different ways to check if an object is null: object obj = ...; obj == null; object.Equals(obj, null); object.ReferenceEquals(obj, null); obj is null; // Equivalent to ReferenceEquals(obj, null) (object)obj == null; // Equivalent to ReferenceEquals(obj, null) obj is not object; // Equivalent… [read more]

Finding concurrency bugs in a .NET application using Coyote

  • Gérald Barré
Coyote is .NET library and tool designed to help ensure that your code is free of concurrency bugs. Concurrency bugs are hard to find and reproduce as they often depends on non-deterministics things such as timeout or message ordering. For instance, if multiple threads are waiting for a locked object, which one will acquired it first? Coyote is able to run a multi-threaded application in a deterministic… [read more]

Debugging a .NET assembly without the source code with Visual Studio

  • Gérald Barré
When using an external closed-source library, it can sometimes be useful to understand how it works and debug it like if it were part of your solution. To display the source code of a DLL when debugging, Visual Studio relies on PDB files (Symbol files) to link compiled code to source code. This means Visual Studio needs to find the PDB file and the .cs files. Visual Studio can load these files either from… [read more]

Understanding the impact of Roslyn Analyzers on build time

  • Gérald Barré
Roslyn analyzers analyze your code for style, quality and maintainability, design and other issues. .NET includes built-ins analyzers (Microsoft.CodeAnalysis.NetAnalyzers), and it's very common to include a few other analyzers such as Microsoft.VisualStudio.Threading.Analyzers, Meziantou.Analyzer, or StyleCop.Analyzers. Roslyn analyzers runs while building the projects. If you enable lots of rules, it… [read more]

Debouncing / Throttling JavaScript events in a Blazor application

  • Gérald Barré
Debouncing and throttling are used to prevent too many events from being processing. For instance, when a user types text in a search bar, you may want to wait until they stop writing for a few milliseconds before executing the search request. This is what debouncing is made for. When using debounce, you will wait for a certain inactivity time before processing an event. In Blazor, there are 2 ways to use… [read more]

Building .NET projects using the Microsoft.Build.Traversal SDK

  • Gérald Barré
Your continuous integration script often looks like dotnet build mysolution.sln and dotnet test mysolution.sln. In my case, I have a solution that contains multiple class libraries and a few WPF projects. I want to create NuGet packages and also test projects on Windows, Linux, and Mac. However, you cannot build WPF projects on Linux or Mac. This means dotnet build fail on these platforms. One way to deal… [read more]

Tracking Cloudflare Worker requests using Application Insights

  • Gérald Barré
This website is hosted on a static website hosting provider and I use Cloudflare CDN to improve the performance. These 2 services allow me to host this website for free even if I got more and more visitors. However, I do not have lots of analytics. For instance, I want to know where the user comes from using the HTTP referer header or if they got a 404. Google Analytics is useful but most users use an… [read more]