Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) 不添加额外的编码提供者 [英] Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) does not add extra encoding providers

查看:53
本文介绍了Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) 不添加额外的编码提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 netcoreapp2.0 控制台应用程序,我需要从 .NET 访问整个编码包.

I am developing a netcoreapp2.0 console application and I need access to the whole encoding package from .NET.

我已经从 此页面 到我的项目并多次清理/恢复项目.

I have already added the System.Text.Encoding.CodePages Version=4.4.0 Nuget package from this page to my project and cleaned/restored the project several time.

但是我无法获得所需的额外编码.

However I can't get the extra encoding I need.

以下代码:

Console.WriteLine(Encoding.GetEncodings().Length);
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Console.WriteLine(Encoding.GetEncodings().Length);

返回:

8
8

并且没有向 Encoding 类添加额外的编码.

and no extra encoding is added to Encoding class.

这些是我在项目中的所有参考资料:

These are all the references I have in my project:

<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.0.0" />
<PackageReference Include="System.Data.HashFunction.xxHash" Version="2.0.0-ci-00012" />
<PackageReference Include="Nager.PublicSuffix" Version="1.1.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />

我在这里做错了吗?

更新

再次重新安装 .NET Core SDK 2.0.2 后,事情开始正常工作,我可以使用 Encoding.GetEncoding() 方法使用扩展的编码代码页,但是 Encoding.GetEncodings() 仍然返回最初的 8 个 Encoding 代码页.

After reinstalling the .NET Core SDK 2.0.2 again, things started to work fine and I can use the extended Encoding code pages using Encoding.GetEncoding() method, however the Encoding.GetEncodings() still returns the initial 8 Encoding code pages.

推荐答案

对于 Gabriel 的建议,它可能在未来也能帮助其他人,我添加此作为答案.

I am adding this as the answer regarding Gabriel's suggestion that it might help other people in the future too.

我清理了 Nuget 缓存,修复了我的.NET Core SDK 2.0.2"安装,执行了解决方案和项目清理"并重建了我的项目,以及 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) 代码开始正常工作.

I cleaned the Nuget cache, repaired my ".NET Core SDK 2.0.2" installation, did a "Solution and Project Cleanup" and rebuilt my project, and the Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) code started to work fine.

现在我可以使用 Encoding.GetEncoding() 方法访问额外的代码页,但是我仍然从 Encoding.GetEncodings() 方法获得相同的编码列表添加额外编码后.

Now I can access the extra code pages using the Encoding.GetEncoding() method, however I still get the same list of encodings from Encoding.GetEncodings() method after adding the extra encodings.

从我的角度来看,Encoding.GetEncodings() 方法应该在添加更多编码后返回所有可用的编码.

From my perspective the Encoding.GetEncodings() method should return all the encodings available after more of them have been added.

这篇关于Encoding.RegisterProvider(CodePagesEncodingProvider.Instance) 不添加额外的编码提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆