Wednesday, June 22, 2022

[.NET 6] Custom Converter for System.Text.Json

Some people asked a question about custom converter for System.Text.Json on Facebook .NET group.
He want user get the specific format from DateTimeOffset (not DateTime)

DateTimeOffset.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fffzzz");
//"2022-06-22 06:28:55.207+00:00"

If using default converter, the result will follow ISO 8601 format

return DateTimeOffset.UtcNow;
//"2022-06-22T05:55:57.4313761+00:00"

And the don't want to use ToString() to achieve it everytime, so the best way is add the custom converter to JsonOptions

Monday, January 3, 2022

WSL2 - Temporary failure in name resolution

WSL2 is good thing, but dunno why some bug it never fixed.

If you are first time install WSL2 and reboot or something like it, it may become no internet connectivity and show error
Temporary failure in name resolution

To fix it, please follow this gitgub issue, JohnnyQuest1983's reply.

The steps can be simple like this
  1. set generateResolvConf=false in /etc/wsl.conf
  2. set dns in /etc/resolv.conf


then use exit or wsl --shutdown, reboot wsl, and it worked, the internet back.