How to read Windows-1252 encoded files with .NETCore and .NET5+

Another day, another lesson learned: modern .NET does not support the Windows-1252 encoding out of the box. Today my colleague was happily porting a legacy NET4+ app to NET6. As usual, the port was super-easy; it would compile and run just fine, so he was surprised when the app crashed reading a few specific XML files. That’s when I was called in. A closer inspection revealed a pattern: all those crashing files were Windows 1252-encoded (the rest, a vast majority, were UTF-8....

August 27, 2021

Will .NET 6 Minimal APIs turn heads?

I am pretty excited about the [Minimal APIs][3] feature that is coming with .NET 6. Three lines of code will be enough to build a fully functional REST microservice1: var app = WebApplication.Create(args); app.MapGet("/", () => "Hello World!"); await app.RunAsync(); If you’re a seasoned ASP.NET MVC/WebApi developer, the snippet caught your attention because, pre-.NET 6, achieving the same result will have you messing with a lot of extra cruft2. I suspect, however, that this feature is not primarily targeted at existing ....

July 14, 2021

My DotNetPodcast interview

Today I was interviewed by Mauro Servienti on the DotNetPodcast. The theme was my experience as an open-source maintainer on both the Python and C# stacks. We also discussed the ongoing evolution of the dotNET ecosystem, touching on a few tangent topics. The recording is in Italian and is available below here. Listen to “Python, Eve, open source e fattura elettronica. Con Nicola Iarocci” on Spreaker.

July 6, 2021

Custom default values for not existing dictionary items (and a lesson learned)

When dealing with dictionaries, a typical problem is when an operation attempts to retrieve an element using a key that does not exist in the dictionary. In .NET, a KeyNotFoundException is raised, and that’s the desired behaviour in most circumstances. Sometimes, however, you know that your program will frequently try to retrieve keys that do not exist. In such cases, it is more efficient to use the TryGetValue method: This method returns the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter is returned (source)...

June 11, 2021

dotnet SmtpClient should not be used

I am very late to the party, but today I learned that the good old dotnet SmptClient is considered obsolete and should not be used. Quoting the documentation: We don’t recommend using the SmtpClient class for new development because SmtpClient doesn’t support many modern protocols. Use MailKit or other libraries instead. (source) Interestingly, Microsoft is recommending a third-party open-source library as an alternative. I hope we’ll see more of that in the future....

May 4, 2021