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.
The following code:
Console.WriteLine(Encoding.GetEncodings().Length);
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Console.WriteLine(Encoding.GetEncodings().Length);
returns:
8
8
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" />
Am I doing something wrong here?
Update
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.
I am adding this as the answer regarding Gabriel's suggestion that it might help other people in the future too.
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.
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.
From my perspective the Encoding.GetEncodings()
method should return all the encodings available after more of them have been added.