偶尔的System.NotSupportedException:没有数据可用于编码1252

Pie*_*pen 1 asp.net-core

在Windows IIS上的.NET Core 2.0中,我正在将一个部分html文件读入字符串:

   string sWelcomeContent = System.IO.File.ReadAllText(welcomepagePath, System.Text.Encoding.GetEncoding(1252));
Run Code Online (Sandbox Code Playgroud)

这很正常,但很少(去年发生过两次),我收到一个错误:System.NotSupportedException:没有数据可用于编码1252.

任何想法为什么会这样?

G43*_*eli 5

System.Text.Encoding.CodePages NuGet包添加到解决方案中,并在应用程序启动类中使用以下代码来注册新的编码.

public void ConfigureServices(IServiceCollection services)
{
    Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

    // more code here
}
Run Code Online (Sandbox Code Playgroud)