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

查看:3592
本文介绍了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.

我已经从System.Text.Encoding.CodePages Version = 4.4.0 Nuget程序包/packages/System.Text.Encoding.CodePages/ rel = nofollow noreferrer>此页面到我的项目,并多次清理/恢复了该项目。

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

并且<$ c没有添加任何额外的编码$ c>编码类。

这些是我在项目中拥有的所有引用:

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个编码页。

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.

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

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天全站免登陆