Creating an HttpClient that uses DNS over Https

 
 
  • Gérald Barré
DNS is a key component of the Internet. It's used to translate a domain name to an IP address. For instance, when you type https://www.meziantou.net in your browser, the browser will query the DNS server to get the IP address of the server hosting the website. Then, the browser will connect to the server using the IP address. A good practice is to rely on the OS configuration to query the DNS server.… [read more]

Enable the new TerminalLogger in .NET 8 SDK automatically

 
 
  • Gérald Barré
In .NET 8, you can use the new TerminalLogger. This terminal logger provides better output than the default console logger. It provides live progression and improves error reporting. However, it's not enabled by default. You need to use the --tl option to enable it (e.g. dotnet build --tl). Instead of adding the flag every time you run a dotnet command, you can enable the new terminal logger by adding the… [read more]

How to get assembly code generated by the JIT for a C# method

 
 
  • Gérald Barré
When you execute a .NET method, the JIT compiles the method to native code. This native code is then executed by the CPU. In this post, I describe how you can inspect the generated assembly code. Using the DOTNET_JitDisasm environment variable Starting with .NET 7, you don't need any complex tools to inspect the generated assembly code. You can use the new environment variable DOTNET_JitDisasm with the… [read more]

Difference between CultureInfo.Get and new CultureInfo

 
 
  • Gérald Barré
When you want to get a CultureInfo object, you can use the static method CultureInfo.GetCultureInfo or the constructor of the CultureInfo class. In this post, I describe the difference between CultureInfo.GetCultureInfo and the constructor of the CultureInfo class. var cultureInfo1 = CultureInfo.GetCultureInfo("en-US"); var cultureInfo2 = new CultureInfo("en-US"); The constructor creates a new instance… [read more]

Making primary constructor parameters read-only

 
 
  • Gérald Barré
C# 12 introduced a new feature called Primary constructor. This feature allows us to define a constructor directly in the class declaration. // You can define a constructor directly in the class declaration. public readonly struct Distance(double dx, double dy) { public readonly double Magnitude { get; } = Math.Sqrt(dx * dx + dy * dy); public readonly double Direction { get; } = Math.Atan2(dy, dx); } This… [read more]