Using source-generated regex in ASP.NET Core route constraints

 
 
  • Gérald Barré
To use the Regex source generator, you need to use .NET 7 and C# 11. Source Generated Regex provides multiple advantags over the traditional regex: Faster startup time as the all the code is generated at compile time. You don't need to parse the regex pattern and generate an optimized code to execute the regex at runtime. Better trimming support as the code is generated at compile time. The code that is… [read more]

Using .NET code from JavaScript using WebAssembly

 
 
  • Gérald Barré
Blazor WebAssembly allows to run a .NET web application in a browser. Starting with .NET 7, you can easily run any .NET method from JavaScript without needing the whole Blazor framework. Let's see how to run a .NET method from JavaScript! First, you need to install the WASM workload, so you can publish the app later: dotnet workload install wasm-tools Then, you can create a new console app: dotnet new… [read more]

Reducing Blazor WASM size by providing custom ICU data

 
 
  • Gérald Barré
The International Components for Unicode (ICU) is a set of libraries that provide Unicode and internationalization support for software applications. Unicode is a standardized encoding system that represents almost all of the written languages of the world. It is used to represent characters in computers, mobile devices, and other digital devices. ICU provides a wide range of functions for working with… [read more]

Detecting breaking changes between two versions of a NuGet package at packaging time

 
 
  • Gérald Barré
I've already talked about preventing breaking changes in the post I fixed a bug. What should I do now?. But technics evolves, and now the .NET SDK provides new features to help NuGet package authors to detect breaking changes between two versions of a NuGet package when building a new version. Starting with .NET 6, the .NET SDK provides a new feature called Package Validation that allows NuGet package… [read more]

Generating a dump file when tests hang on a CI machine

 
 
  • Gérald Barré
I recently investigated an issue where the tests hang on the CI. It's easier to debug when issues happen on your machine as you can easily attach a debugger and see what's going on. But in this case, the tests were hanging on the CI and I couldn't attach a debugger. I had to find an alternative way to debug the issue. dotnet test has many useful options. One of them is --blame-hang which allows to take a… [read more]

Prevent http requests to external services in unit tests

 
 
  • Gérald Barré
This blog post is part of The C# Advent Calendar, a series of 50 posts about C#. Be sure to check out the rest of the blog posts in the calendar! Flakiness in unit tests refers to the tendency of a test to sometimes pass and sometimes fail, even when there has been no change to the code being tested. This can happen for a variety of reasons, but the end result is that the test is not reliable, and cannot… [read more]