The files you want to read can be in 2 different encodings, UTF-8 and Windows-1251. UTF-8 is normally recognized, but 1251 it cannot recognize correctly. What encoding of the file before it was processed is not known. What are the possible solutions?
csvReaderConfig = new CsvConfiguration(CultureInfo.InvariantCulture)
{
Delimiter = ";",
BadDataFound = null,
MissingFieldFound = null,
//Encoding = Encoding.GetEncoding(1251) //default utf-8
};
using (var reader = new StreamReader(path))
{
try
{
using (var csv = new CsvReader(reader, csvReaderConfig))
{
records = csv.GetRecords<object>().ToList();
}
}
catch (Exception ex)
{
}
}