[.NET Core] System.NotSupportedException: No data is available for encoding 950 錯誤解決方法

熱門文章 (Popular Post)

Posted by : Duran Hsieh 2019-11-24

問題描述 (Error Descrption)

在 .NET Core 內使用 Encoding.GetEncoding(950) 方法時,出現錯誤訊息: System.NotSupportedException: No data is available for encoding 950





解決方法 (Solution)

你可以加上  Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 解決這個問題,其主要的原因為簡化了編碼,導致部分編碼不包含在當中。

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

using (var reader = new StreamReader("C:\\PFE\\Employee.csv", Encoding.GetEncoding(950), true))
{
    var line = reader.ReadToEnd();
    Console.WriteLine(line);
}

參考資料

VS Code C# - System.NotSupportedException: No data is available for encoding 1252 - stack overflow


Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Duran Hsieh @ Duran 的技術冶煉廠 - Date A Live - Powered by Blogger - Designed by Johanes Djogan -