Making the latest C# language features available in older .NET versions

In a C# library I’ve been working on, I wanted to use C# 9.0’s init keyword. Quoting the documentation: The init keyword defines an accessor method in a property or indexer. An init-only setter assigns a value to the property or the indexer element only during object construction. This enforces immutability so that once the object is initialized, it can’t be changed again. Consider the following class: public class Person { public string FirstName { get; init; } } You can initialize it like this: ...

February 4, 2023

A quick preview of the Blazor United prototype for .NET8

Steve Sanderson, the original creator of Blazor, recently posted a quick peek at some of the new Blazor prototypes they are experimenting with for .NET 8. I think this looks great. Mixing client and server is a brilliant concept. Essentially one would be served with server-side Blazor on the first landing. While using the app, a background task would download the client-side stuff, ready to be consumed at any subsequent access. ...

January 28, 2023

On implementing the ASP.NET Core 7 rate-limiting middleware

Today, my last self-assigned duty before the Christmas break was to migrate our in-house rate-limiting implementation (based on the AspNetCoreRateLimiting third-party package) to the new, shiny rate-limiting middleware introduced by ASP.NET Core 7. While the process was relatively straightforward, I stumbled upon a few quirks I want to annotate here. Our use case is simple. We use what the ASP.NET Core 7 documentation defines as a “fixed window limiter.” It uses a specified time window to limit requests. When the time window expires, a new time window starts, and the request limit is reset. Consider the following code (for convenience, I’m using an extension method): ...

December 23, 2022

First impressions on JetBrains Rider 2022.3 update

Today I upgraded to JetBrains’ Rider 2022.3. Startup speed has been enhanced, and full .NET 7 and C# 11 support is included. So far, my favorite feature is the conversion of regular and verbatim strings into their raw counterparts (it’s often the small, simple things.) My second best is the fulls upport for WSL2 remote development. This one took a good while to come out of the trenches, but better late than never, I’d say. ...

December 12, 2022

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 .NET team. Starting with .NET 5, performance gains have been skyrocketing. .NET 6 was a lot faster than 5, and now, well, I’m surprised by the remarkable performance improvements in .NET 7. Stephen Toub posted a remarkably long (255 printed pages!) in-depth analysis of the performance improvements in .NET 7. one That was followed by articles dedicated to ASP.NET Core 7 and MAUI 7 performance gains. At .NETConf 2022, a particular slide caught everyone’s attention. ...

December 4, 2022

FatturaElettronica v3.4 released

Today I released v3.4 of FatturaElettronica, a .NET open source project that allows validation and de/serialization of electronic invoices adhering to the standard defined by the Italian “Agenzia delle Entrate”. It’s doing very well for such a niche project, with downloads now well beyond the one hundred thousand mark. Be aware that this release anticipates support for v1.7.1 of the specification going into effect on October 1, 2022. For more information, see the appropriate ticket and the changelog. ...

September 9, 2022

I'm a Microsoft MVP once again

I am happy and humbled to have been awarded the Microsoft MVP Award for the seventh consecutive year. July 1, the award assignation day, always comes with curiosity and a bit of trepidation. Being a member of the MVP community has been a very positive experience for me, especially in the years before COVID, when the MVP Summit, the main MVP event, was held in person in Seattle at the Microsoft HQ. That assembly of experienced developers from all over the world is an exhilarating experience. Smart guys and gals from different cultures gather to meet the people responsible for their daily drivers’ tools and technologies. There are countless networking possibilities, both with fellow MVPs and Microsoft personnel. ...

July 27, 2022

My Playwright session at WebDay 2022

If you understand Italian, the recording of my Playwright session at UGIdotNET’s WebDay 2022 is now available on YouTube1. Playwright is a phenomenal cross-browser, cross-platform, cross-language, single-API, mobile-friendly front-end testing tool. I’m looking forward to giving the same session in English sooner or later, but I should first win my laziness and start looking for exciting events with open CFPs. If you happen to know one, please let me know. A couple weeks later I also presented at DevRomagna, the local meetup I run. [rss]: https://nicolaiarocci.com/index.xml [tw]: http://twitter.com/nicolaiarocci [nl]: https://buttondown.email/nicolaiarocci ↩︎ ...

April 1, 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: public static void M(string s) { if (s is null) { throw new ArgumentNullException(nameof(s)); } // Body of the method } Would be abbreviated by adding !! to the parameter name: ...

February 27, 2022

My ASP.NET 5 migration to .NET 6

I spent the last few days migrating our ASP.NET REST services, MVC web applications and Blazor server apps to .NET 6. Overall the process was pretty straightforward. The few issues I went through were easy to solve and well documented. Things got more involved with the EF Core 6 transition, especially with the Npgsql Entity Framework Core Provider. The official ASP.NET Core 5.0 to 6.0 migration guide was my first stop. It offers the perfect entry point, rich with in-depth links. At this stage, I am not interested in switching to the new .NET 6 minimal hosting model (aka Minimal APIs). I think it’s a significant improvement, and we will likely adopt it for new projects, but our production projects aren’t going to be refactored right away. Should minimal APIs also prove to be remarkably performant, we’ll reconsider them1. ...

November 14, 2021