Especially if you are reading something from excel you may get below issue somewhere around the process.
"No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method."
This happens due to the encoding difference in .Net core.
This issue can be easily be fixed by adding the below line of code in your excel handling methods.
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
Don't forget to add the corresponding NuGet package also.
So while excel reading may look like this.
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); FileStream stream = File.Open(ExcelRepFile, FileMode.Open, FileAccess.Read); IExcelDataReader excelReader = null; try { if (ExcelRepFile.EndsWith(".xls")) { excelReader = ExcelReaderFactory.CreateBinaryReader(stream); } if (ExcelRepFile.EndsWith(".xlsx")) { excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); } } catch (Exception) { throw; }
Thanks Perfect
ReplyDeleteExcellent
ReplyDelete