Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code C# - System.NotSupportedException: No data is available for encoding 1252

I am trying to use ExcelDataReader to read an .xls file on Ubuntu. I am using VS Code with C#. Here is the code:

var stream = File.Open(filePath, mode: FileMode.Open, access: FileAccess.Read); var reader = ExcelReaderFactory.CreateReader(stream); 

I also tried this:

var reader = ExcelDataReader.ExcelReaderFactory.CreateBinaryReader(stream); 

When I run, I am getting the following exception:

Unhandled Exception: System.NotSupportedException: No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. at System.Text.Encoding.GetEncoding(Int32 codepage)

I already installed the libmono-i18n-west4.0-cil (tried also with libmono-i18n4.0-all) as I found out some people recommending this, but the problem persists. Also installed the package System.Text.Encoding.CodePages without success.

Can anyone help to solve this?

like image 214
Dalton Cézane Avatar asked Mar 11 '18 01:03

Dalton Cézane


People also ask

Is VS Code good for C?

C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development on Windows, Linux, and macOS.

Can you code C in VS?

Yes, you very well can learn C using Visual Studio. Visual Studio comes with its own C compiler, which is actually the C++ compiler. Just use the . c file extension to save your source code.

Why C is not working in VS Code?

You have to change it so it runs in the terminal. Go to the menu Code > Preferences > Settings. In the User tab on the left panel, expand the Extensions section. Find and select Run Code Configuration.


1 Answers

I faced the same problem with .net Core application. I added the System.Text.Encoding.CodePages nuget package and registered the encoding provider before ExcelReaderFactory.CreateReader(stream) which resolved the issue.

System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); //open file and returns as Stream using (var stream = File.Open(fileName, FileMode.Open, FileAccess.Read)) {       using (var reader = ExcelReaderFactory.CreateReader(stream))       {       } } 
like image 123
Pervez Alam Avatar answered Sep 20 '22 02:09

Pervez Alam