So, today, while migrating a project to .Net Core, I've encountered a failing unit test that told me this:
Code page 1252 ist the Western European standard code page, but I was obviously missing it. That's where I found svicks post on StackOverflow, which basically explained what went wrong:
In .Net Core, available encodings need to be registered before you can access them.
First, you need to import the System.Text.Encoding.CodePages dependency and define a compilation value (I chose NETCORE) in your project.json:
"frameworks": { "netcoreapp1.0": { "imports": [ "dnxcore50", "portable-net45+win8" ], "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" }, "System.Text.Encoding.CodePages": "4.0.1" }, "buildOptions": { "define": [ "NETCORE" ] } }, "net461": {} }
Next, register the provider from within your code via conditional compilation:
#if NETCORE Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #endif
Happy Encoding=)