RSSAmplifier

Blog

Maarten Balliauw {blog}

Web development, .NET, C#, Azure, ...

blog.maartenballiauw.beRSS feed ↗479 posts

Latest posts

Keyed Services (Named registrations) in .NET Service Provider

You have an IMessageSender interface, with two implementations: EmailMessageSender and SmsMessageSender. You register both, and now the question is which one gets injected into your OrderConfirmationService constructor. The answer, unhelpfully, is whichever was registered last. This may also introduce subtle, unexpected bugs when new services are registered.

So, I wrote a fiction book. Meet "The Side Project".

For as long as I can remember, I’ve been writing non-fiction. Blog posts, documentation, technical guides, a couple of books about NuGet, and ASP.NET MVC 1.0 which still sells one copy per quarter, amazingly. Somewhere in the back of my mind, I have always thought I’d want to write fiction at some point. But about what? Early 2025, working on my own side project, I got the idea for a story, and… I…

TimeProvider and the End of Untestable DateTime.Now

DateTime.Now is one of those calls that looks harmless until you try to write a test around it. It’s a static property that reads the system clock, and there’s no way to control what it returns without wrapping it in something injectable. I have wrapped it in codebases, and others have too. Unfortunately, everyone wrapped it their way. Since .NET 8, we can all stop reinventing the same abstraction…

Discriminated unions in C# and .NET 11 (for real this time)

Back in 2023, I wrote about discriminated unions in C# and how C# developers had to work around the lack of language support using things like ASP.NET Core’s Results<> type or the OneOf NuGet package. Real C# language support (csharplang issue #113) had been open for years with no sign of a proper solution. Well, the wait is over. C# 15, shipping with .NET 11 (preview), introduces first-class…

What is IdentityServer and When Do You Need it?

Earlier this week at Duende Software, we had a prospect reach out that wanted to implement IdentityServer in their solution. Their application consisted of one ASP.NET Core application with local users, no mobile applications or other clients, no API surface, and no plans in the roadmap to move towards an architecture with any of these. All they wanted was to add external authentication to Google.

Time for a change... Moving from JetBrains to Duende Software

At the start of 2025, I will be joining Duende Software to help drive customer success and advocate for IdentityServer and other tools and frameworks built by the company. For close to 12 years, I have been working at JetBrains as a Developer Advocate. Mainly for .NET, but also for other fantastic developer tools. In recent years, I have grown to lead the .NET Advocacy team, and later head the…

Talk - Bringing C# nullability into existing code

The C# nullability features help you minimize the likelihood of encountering that dreaded System.NullReferenceException. Nullability syntax and annotations give hints as to whether a type can be nullable or not, and better static analysis is available to catch unhandled nulls while developing your code. What’s not to like? Introducing explicit nullability into an existing code bases is a Herculean…

Test-Driving Windows 11 Dev Drive for .NET

At Build 2023 back in June, Microsoft announced a new form of storage volume for Windows 11: Dev Drive. In October 2023, support for Dev Drive was shipped as a Windows Update and now available to anyone using the latest version of Windows 11.

Provide opt-in to experimental APIs using C#12 ExperimentalAttribute

When writing libraries and frameworks that others are using, it’s sometimes hard to convey that a given API is still considered “experimental”. For example, you may want to iterate on how to work with part of the code base with the freedom to break things, while still allowing others to consume that code if they are okay with that.

Discriminated Unions in C#

Discriminated unions have been a long-standing request for C#. While F# users have had discriminated unions for years, C# developers will have to wait a bit longer. What discriminated unions allow you to do is tell the compiler (and other tooling like your IDE) that data can be one of a range of pre-defined types.

Running Large Language Models locally – Your own ChatGPT-like AI in C#

For the past few months, a lot of news in tech as well as mainstream media has been around ChatGPT, an Artificial Intelligence (AI) product by the folks at OpenAI. ChatGPT is a Large Language Model (LLM) that is fine-tuned for conversation. While undervaluing the technology with this statement, it’s a smart-looking chat bot that you can ask questions about a variety of domains.

Getting rid of warnings with nullable reference types and JSON object models in C#

In my blog series, Nullable reference types in C# - Migrating to nullable reference types, we discussed the benefits of enabling nullable reference types in your C# code, and annotating your code so the compiler and IDE can give you more reliable hints about whether a particular variable or property may need to be checked for being null before using it. We ended the series with a curious case: how…

Mastodon on your own domain without hosting a server

Like many in the past week, I have been having a serious look at Mastodon as an alternative to Twitter. Mastodon is a social network that is distributed across many servers that have their own smaller communities, and federate with other servers to provide a more “global” social network. There are many servers out there that you can choose from. Alternatively, you can also self-host your Mastodon…

Rate limiting in web applications - Concepts and approaches

Your web application is running fine, and your users are behaving as expected. Life is good! Is it, though…? Users are probably using your application in ways you did not expect. Crazy usage patterns resulting in more requests than expected, request bursts when users come back to the office after the weekend, and more!

ASP.NET Core rate limiting middleware in .NET 7

Rate limiting is a way to control the amount of traffic that a web application or API receives, by limiting the number of requests that can be made in a given period of time. This can help to improve the performance of the site or application, and to prevent it from becoming unresponsive. Starting with .NET 7, ASP.NET Core includes a built-in rate limiting middleware, which can be used to rate…

How to test ASP.NET Core Minimal APIs

How do you test that your ASP.NET Core Minimal API behaves as expected? Do you need to deploy your application? Can you write tests with frameworks like xUnit, NUnit, or MSTest? In this post, you will learn the basics of testing ASP.NET Core Minimal APIs. You’ll get started with testing a “hello world” endpoint, and then test a more complex API that returns JSON data. You’ll finish with…

Techniques and tools to update your C# project - Migrating to nullable reference types - Part 4

Previously, we saw how you can help the compiler’s flow analysis understand your code, by annotating your code for nullability. In this final post of our series, we’ll have a look at the techniques and tools that are available to migrate to using nullable reference types in an existing code base. In this series: As we have seen in a previous post, it can be an overwhelming experience to go all-in…

Annotating your C# code - Migrating to nullable reference types - Part 3

In the previous post, we looked at some internals of C# nullable reference types, and the nullable annotation context. Today, let’s look at the many options for annotating your code and various ways to help the flow analysis understand your code. As a result, you (and anyone consuming your libraries) will get better and more reliable hints from the IDE and the C# compiler. In this series: So far,…

Internals of C# nullable reference types - Migrating to nullable reference types - Part 2

In the previous post, we saw that with nullable reference types enabled, you get better static flow analysis when working on your code. While nullable reference types don’t give you runtime safety, the design-time and compile-time help is priceless! In this post, we’ll look at some internals of how C# nullable reference types work, and how the C# compiler and IDE use the nullable annotation…

Nullable reference types in C# - Migrating to nullable reference types - Part 1

The C# nullability features introduced in C#8 help you minimize the likelihood of encountering that dreaded System.NullReferenceException. Nullability syntax and annotations give hints on whether a type can be nullable or not. Better static analysis is available to catch unhandled nulls while developing your code. What’s not to like? Introducing explicit nullability into an existing code base is…

A journey towards SpeakerTravel - Building a service from scratch

For close to two years now, I’ve had SpeakerTravel up & running. It’s a tool that helps conference organizers to book flights for speakers. You invite speakers, they pick their flight of choice (within a budget the organizer can specify), and the organizer can then approve and book the flight with a single click. In this post, I want to go a bit into the process of building this tool. Why I…

Custom bindings with Azure Functions .NET Isolated Worker

If you’re building workloads on Azure Functions, there’s a good chance you’ve looked at building custom bindings. Custom bindings can greatly reduce the boilerplate code you have to write in an Azure Function, so you can focus on the logic in your function instead. There are various examples of custom bindings out there, including several that I wrote while working on Indexing and searching…

Running a .NET application as a service on Linux with Systemd

In this post, let’s see how you can run a .NET Core / .NET 5 application as a service on Linux. We’ll use Systemd to integrate our application with the operating system and make it possible to start and stop our service, and get logs from it. To build my supply chain attack with .NET, I needed to host a DNS server to capture the hostnames sent to me. Let’s use that as an example!

Building a supply chain attack with .NET, NuGet, DNS, source generators, and more!

For a couple of months now, I’ve been pondering about what tools are at your disposal in .NET to help build and execute a supply chain attack. My goal was to see what is available out there, and what we, as .NET developers, should be aware of. Prepare for a long read! Now, forget that short introduction, and let’s start anew…

The process, thought and technology behind building a friendly .NET SDK for JetBrains Space

Early December 2020, we released JetBrains Space. Along with it, we built a Kotlin SDK and a .NET SDK. In this post, I want to walk you through the process of building that .NET SDK. This is another half-book blog post, so I’ve included a table of contents for you to jump to the parts you may be interested in. I’ve tried my best to build up the story, so of course, reading this post in full is…

Export Office 365 calendar events to JetBrains Space using the Microsoft Graph API, the JetBrains Space SDK, and automation

Chances are you keep a personal calendar, maybe a family calendar, and a work calendar. Working from home, it’s super important to keep these calendars more or less in sync. Colleagues book meetings because your work calendar shows you’re available, while in reality you’ve planned to do some errands or maybe pick up your kids from school.

Producer/consumer pipelines with System.Threading.Channels

Last week, I came across the following question: “Is there an async producer/consumer collection these days in .NET?” Why yes, there is! Using System.Threading.Channels, we can create producer/consumer pairs, and we can even chain them together in a pipeline. In this post, I will try to explain concurrency, producer/consumer, and System.Threading.Channels concepts using a practical example, to…

A sustainable NuGet marketplace will have to compete with the NuGet gallery

Yesterday, Aaron Stannard posted some awesome news for the .NET community: the introduction of Sdkbin. Sdkbin is targeted at solving the OSS sustainability problem by automating the majority of the sales, fulfillment, licensing, and accounting needed to sell libraries, frameworks, and support plans. It’s (roughly speaking) an App Store, delivered as a NuGet feed. This seems like a great idea, and…

Run Azurite in Docker with Rider and keep Azure Storage data local to a solution

In this blog post, we’ll see how we can use Azurite, an open source Azure Storage API compatible server (emulator), in Docker, and how to run it from JetBrains Rider. We can use Azurite in Docker to keep Azure Storage data local to a solution, and, for example, have different blobs and queues for different Azure Functions projects. Ever since I started playing with Azure back in 2008, I’ve been…

Referencing a Specific Assembly from a NuGet Package

In this post, I’ll describe a little trick I used while building a Rider plugin for XAML Styler, which is referencing a specific assembly from a NuGet package. Let’s start with some background on why I needed this, followed by how to reference a specific assembly from a NuGet package. If you don’t care about the background, feel free to skip the first section.

Building an ASP.NET Core Tag Helper to Show/Hide UI Elements based on Authorization

In this post, let’s see how we can create an ASP.NET Core Tag Helper to show or hide UI elements based on authorization policies. But before we do so, let’s start with a quick introduction outlining why you may want to do this. The web front-end of SpeakerTravel, a side project that helps simplify travel booking for speakers at conferences and events, is built using ASP.NET MVC and Razor Pages. As…

Streaming a Community Event on YouTube Using StreamYard

Last week, I wrote a blog post a book about Streaming a Community Event on YouTube - Sharing the Technologies and Learnings from Virtual Azure Community Day. I ended that post with an appendix of things I’ve looked into but have no experience with. That… changed! Our Azure User Group held its first virtual session yesterday. The social aspect of hanging out with a group of peers was definitely…

Streaming a Community Event on YouTube - Sharing the Technologies and Learnings from Virtual Azure Community Day

Earlier this week, our Belgian Azure User Group has been part of the Virtual Azure Community Day (VACD). An online event hosted by user groups from Belgium, the Netherlands, France and Bulgaria. All online and streamed to YouTube, and organized and executed in ~2 weeks. Many have asked how we have done the YouTube streaming, and that’s what I want to share in this blog post, together with our…

Can .NET Core Framework Assemblies be Mapped back to Individual NuGet Packages? A Detective Story

My friend and colleague Matt Ellis has this habit of nerd sniping me. Sometimes intentional, sometimes accidental. Today, he asked whether we could have a quick look at an issue together, which ended up being a nerd snipe of the latter category. Here’s a blog post about how the new .NET project format references framework assemblies, and how it seems to be impossible to map those back to…

Monitoring Twitter with Azure LogicApps and JetBrains Space

In the .NET team at JetBrains, we try to be as responsive as possible on Twitter when there are mentions of ReSharper, Rider, or any of the profiling tools. Many of our developer advocates, as well as the development team, QA and marketing, are active on Twitter and keep an eye on what’s being talked about, to try and help out wherever and whenever they can.

Deserializing JSON into polymorphic classes with System.Text.Json

While working on SpaceDotNet, a strong-typed client SDK to access the JetBrains Space HTTP API, I came across a scenario to deserialize JSON into polymorphic classes. In this post, I’ll explain how to write a custom JsonConverter for System.Text.Json to help with deserialization for such cases.

Invoking non-HTTP Azure Functions over HTTP to make development easier

This week, I was presenting at IglooConf (Indexing and searching NuGet org with Azure Functions and Search). During one of the demos, I casually used a feature we shipped with the latest Azure Toolkit for JetBrains Rider: when the Azure Functions host is running on a development machine, Rider lets us trigger functions from the gutter by generating an HTTP request for it.

Making API calls using the access token and refresh token from an ASP.NET Core authentication handler

Right now, I’m having fun building a .NET Core client library for JetBrains Space. Part of that client library will be ASP.NET Core authentication, to help in making authentication with your Space organization easy. Think of something like this: This should look very familiar if you are building an ASP.NET Core application that uses something like Microsoft Account, Google, Azure Active…

How does the ASP.NET Core SPA development experience work with React, Angular and VueJS?

Many developers are building Single-Page Applications (SPAs) using popular frameworks like Angular, React or VueJS. They all come with an easy way to generate all required HTML, CSS, JavaScript and Webpack artifacts required to deploy to production, usually an NPM script like npm run build away. Having to build all those artifacts multiple times while developing on our local machine is not too…

Don't use Azure Functions as a web application

I know, I know. That title is probably a bit too harsh and opinionated. But it got your attention, right? A friend of mine this week asked me whether they could use middleware in their HTTP-triggered Azure Functions, ideally even the same ones they use in ASP.NET Core applications. After all, the SDK comes with HTTP triggers that seem to use the same infrastructure, right? My immediate response…

What happens after submitting a session in a Call for Papers?

In 2013, I was asked to be part of a conference agenda committee. Since, I have been part of a couple more, for conferences in different parts of the world. Being “on the other side” of a Call for Papers has been very interesting, and taught me that this is a difficult job. There’s lots of reading, discussion, re-reading and more discussion involved. At some point there comes the rewarding bit of…

Indexing and searching NuGet.org with Azure Functions and Search

In an application I’m writing, I need to deserialize some JSON. I know the class to use is JsonConvert, but which NuGet package was that type in again? Granted, that’s an obvious one. Yet, there are many uses for a “NuGet reverse package search” that helps finding the correct NuGet package based on a public type.

Talk - Indexing and searching NuGet.org with Azure Functions and Search - NDC Oslo - Norway - Oslo

This week, I had the opportunity to speak at NDC Oslo. The talk I did was “Indexing and searching NuGet.org with Azure Functions and Search”, which covers a story of re-building an existing service using a serverless approach, on Azure Functions. As promised, here are the slides as well as the recording. Which NuGet package was that type in again? In this session, let’s build a “reverse package…

Talk - Approaches for application request throttling and Indexing and searching NuGet.org with Azure Functions and Search - Cloud Developer Days - Poland - Krakow

Thanks to the folks organizing Cloud Developer Days Poland, I had the opportunity to give two talks in Krakow, Poland this week: As promised, here are the slides for both.

Talk - Exploring .NET memory management - a trip down memory lane - CodeStock 2019 - Knoxville, TN - USA

That was fun! I had the opportunity to present at CodeStock 2019 in Knoxville, TN (USA). The conference is for the community, by the community, which means lots of enthusiast people around. The talk I did was Exploring .NET memory management - a trip down memory lane. Slides are available below. Demo code is available from GitHub.

Talk - Approaches to application request throttling and Microservices for building an IDE - The innards of JetBrains Rider - ConFoo - Canada - Montreal

This week, I had the privilege to visit ConFoo Montreal for the third time. It’s a great conference that has attendees interested in lots of technologies such as PHP, Java, .NET and more. Even better: I got to deliver two talks: As promised, here are the slides for both.

Talk - Microservices for building an IDE - The innards of JetBrains Rider - TechDays 2019 - Finland - Helsinki

The nice folks of TechDays Finland provided me with the opportunity to speak about Microservices for building an IDE - The innards of JetBrains Rider. It was nice to be able to talk about some of the internals, architecture and design decisions that were made while building a .NET IDE - Rider. If you’re interested in the slides, find them below. This story is also avilable as an article on CODE…

ASP.NET Core on IIS Express - Empty error starting application

Usually on my development machine, I run ASP.NET Core applications in Kestrel. It’s easy to do, the project templates .NET Core provide create a nice launchSettings.json to start it from the command line, etc. However, I was asked to help someone out with hosting ASP.NET Core in IIS Express. Great! The default launchSettings.json contain an entry for that as well, so I ran dotnet run…

Unit testing for ValidateAntiForgeryToken and clever navigation in the ReSharper/Rider test runner

We all know it’s important to prevent Cross-Site Request Forgery (CSRF) attacks against our application. Unfortunately, our inherited code base has zero measures implemented - not one action methods with a [ValidateAntiForgeryToken] attribute in sight!

Tracking down action methods that need ValidateAntiForgeryToken using Structural Search and Replace

As discussed in the previous post, we all know it is important to perform validations to prevent a Cross-Site Request Forgery (CSRF) attack against our application. Imagine inheriting a code base that has zero measures implemented? How would you find which action methods need a [ValidateAntiForgeryToken]? Today, we will look at using ReSharper to find all action methods that need…