Convert DateTime to user's time zone with Blazor in .NET 8

 
 
  • Gérald Barré
This post is an update of the original post Convert DateTime to user's time zone with server-side Blazor to take advantage of new .NET 8 features. It is inspired by the following pull request in dotnet/aspire When you display DateTime data to a user, you may want to convert the value to the user's time zone. With server-side Blazor, the code is executed on the server, so DateTime.Now corresponds to the… [read more]

Generate OpenAPI specification at build time from the code in ASP.NET Core

 
 
  • Gérald Barré
The OpenAPI specification is a powerful tool to describe and document APIs. It is a standard that allows you to define the structure of your API, including the endpoints, the request and response models, and the security requirements. The OpenAPI specification is a JSON or YAML file that can be used to generate documentation, client libraries, and server stubs. Most .NET developers generate the… [read more]

Set a blank page for new tabs in Microsoft Edge

 
 
  • Gérald Barré
Microsoft Edge can be configured using the setting pages edge://settings. However, some settings are not available in the UI. For instance, you cannot replace the new tab page. You can only configure the content of the page... So, you have to stick with the Edge-like page with news and other stuff you don't care about. Hopefully, you can configure Microsoft Edge using policies. There are multiple ways to… [read more]

Optional parameters may appear in the middle of the parameter list

 
 
  • Gérald Barré
In .NET, optional parameters are not always the last parameters. While C# does not allow the declaration of optional parameters in the middle of the parameter list, it is possible to do so in IL or from other languages like VB.NET or F#. Also, the compiler may lower some features and create methods with optional parameters in the middle of the parameter list. Why does it matter? If you write a source… [read more]

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]