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

Making C# and OmniSharp play well with Neovim

I’ve recently moved away from my custom Neovim configuration to embrace LazyVim. LazyVim is a Neovim setup with sane default settings for options, autocmds, and keymaps. It boldly aims to transform Neovim into a full-fledged IDE that is easy to extend and customize. It comes with a wealth of plugins pre-configured and ready to use, and it is also blazing fast. Elijah Manor has a fantastic introductory video on YouTube; I suggest you take the time to look at it....

March 3, 2023

My Top 7 New Features in .NET 7

The other day we did a .NET 7 Spotlight event at this month’s DevRomagna meetup. The speakers were Ugo Lattanzi and me. In my session, I chose to talk about my top 7 new features in .NET 7 (pun intended.) What follows is a mix of my preparation notes and what I ended up really saying1. 1. Performance Since the initial release of “new dotnet” (.NET Core), performance has always been a critical goal for the ....

December 4, 2022

Parameter null-checking added to C# 11 Preview

The first preview of C# 11 is out, and well, I think I like what I see. I dig the new List patterns and am a fan of allowing newlines in the “holes” of interpolated strings. Parameter null-checking is a bit contentious, and it’s good that they are releasing it in preview one and asking for feedback. In a nutshell, they want to spare us a lot of boilerplate. Code like this:...

February 27, 2022