On C# and .NET quick release cycle

I sat to jot down a quick introduction to my C# 13 What’s New and Interesting session at the upcoming .NET Conference Italia 2024 next week, and what I ended up with instead is a long rant or, should I dare, stream of consciousness that is certainly inappropriate for a five-minute introduction. I’ll have to cut most of it down, especially on the personal story part, but my site might be a good place to host it in all its completeness....

December 9, 2024

How to handle custom claims in an Open ID Connect-authenticated ASP.NET Core app

Today, I learned how to handle custom claims in an Open ID Connect authenticated ASP.NET Core app. The scenario goes like this. I have an ASP.NET Core app that authenticates with Open Id Connect. It receives a bearer token from the authentication server. Besides OIDC claims, this token has been forged with additional custom claims for use in the app. However, only ODIC claims exist when I parse HttpContext.User.Identity.Claims in my middleware....

May 31, 2024

C# 12 Collection Expressions

This is a follow-up post to C# 12 Primary Constructors. Like that article, this one originates from the preparation notes for my presentation at the ABP Dotnet Conference 2024. I love collection expressions. Like primary constructors, collection expressions will see a significant adoption in the long run. Collection expressions introduce a new way to initialize common collection values in a terse, unified syntax. This is how we initialize collections today:...

May 10, 2024

C# 12 Primary Constructors

I wrapped up my C# 12 session at the ABP Dotnet Conference 2024, and I wanted to share the take-home points, at least about the most relevant features in this language version. Posting the slides made no sense as they were minimal; all the content was packed in the live demo. In a follow-up post, I plan to address Collection Expressions (done) and maybe “type any aliases”; this is about Primary Constructors....

May 9, 2024

I am speaking at ABP Dotnet Conf'24

I am thrilled to have the opportunity to present at an international conference once again. On May 9th, I will speak at the ABP Donet Conf'24. My session, titled C #12: What’s New and Interesting, is on a topic I’m passionate about. With the alignment of C# and Dotnet Core release cycles, the C# release cadence has increased (we’re on a yearly cycle now), while feature quantity has reduced for individual releases, which is good....

April 15, 2024
Early in the morning at the Microsoft House in Milan. Preparations underway

Video of my C# 12 session at .NET Conference Italia 2023

The video and slides of my C# 12 session at .NET Conference Italia 2023 is finally available online. Unfortunately it’s just my voice and my laptop screen, and that’s too bad because the location was as cool as it can get, and the room was packed. It is in Italian1 and you need to login in order to see it (sorry, I don’t have control over it.) I also submitted to several international conferences; let’s see what happens....

January 26, 2024

How to implement a PKCE code challenge in C#

Today’s fun was implementing OAuth2’s RFC 7636’s PKCE (Proof Key for Code Exchange) in C#. It’s relatively straightforward, but I decided to share my implementation should it be helpful to someone else out there. PKCE is an extension to the Authorization Code flow to prevent CSRF and authorization code injection attacks. [..] It was originally designed to protect the authorization code flow in mobile apps, but its ability to prevent authorization code injection makes it useful for every type of OAuth client, even web apps that use client authentication (source)....

January 17, 2024

How to use XmlWriter along with StringWriter to properly serialize a UTF-8 string

Today, I (re)learned how to serialize an XML to a UTF-8 string. Like all the other times I did this, I got backstabbed by StringWriter, which only supports UTF-16. A simple code snippet like this: await using var sw = new StringWriter(); await using var w = XmlWriter.Create(sw, new() { Async = true }); ... await w.FlushAsync(); return sw.ToString(); Will emit this output: <?xml version="1.0" encoding="utf-16"?><... There’s nothing inherently wrong with UTF-16, but XML is usually UTF-8, so one must do something about it....

November 9, 2023

LINQ DistinctBy on a property for .NET Standard and older .NET versions

Today I learned how to implement a custom Enumerable.DistinctBy extension method that returns distinct elements from a sequence according to a specified key selector function. .NET 6 and its successors have the method built in within LINQ, but I needed it in a .NET Standard 2.0 class library, so I was out of luck. My implementation is simple, not different from others I found online, and should also work fine with old ....

October 25, 2023

Homebrew and .NET 8 Preview don't like each other

Today I learned that .NET 8 Preview could play better with Homebrew (or vice-versa). I’m working on a C# 12 presentation for our local developer meetup, and for that, I wanted .NET 8 Preview to run side by side with version 7 on my Mac. As version 7 was initially installed with Homebrew, I also wanted to install version 8 Preview with Homebrew, but that recipe was unavailable. Not perfectly happy with that, I fell back to the stand-alone installer, expecting problems....

June 13, 2023