Shift-JIS on .NET Core v3

Respect for Shift-JIS.

Introduction

C# code is here:

1
2
using System.Text;
Encoding.GetEncoding("Shift_JIS"); # Crash !!!!!!!!!!

The exception detail is here:

System.ArgumentException: ''Shift_JIS' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. '

How to respond

Act the below steps:

  1. Add System.Text.Encoding.CodePages from NuGet (In this post, use v4.5.1)
  2. Add Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) to your code

Conclusion

1
2
3
using System.Text;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Encoding.GetEncoding("Shift_JIS"); # Don't crash