Why can’t I convert from ‘System.IO.StreamWriter’ to ‘CsvHelper.ISerializer’?

There was a breaking change with version 13.0.0. There have been many issues with localization, so @JoshClose is requiring users to specify the CultureInfo they want to use. You now need to include CultureInfo when creating CsvReader and CsvWriter. https://github.com/JoshClose/CsvHelper/issues/1441

private void ExportAsCSV()
{
    using (var memoryStream = new MemoryStream())
    {
        using (var writer = new StreamWriter(memoryStream))
        {
            using (var csv = new CsvHelper.CsvWriter(writer, System.Globalization.CultureInfo.CurrentCulture)
            {
                csv.WriteRecords(people);
            }

            var arr = memoryStream.ToArray();
            js.SaveAs("people.csv",arr);
        }
    }
}

Note: CultureInfo.CurrentCulture was the default in previous versions.

Consider

  • CultureInfo.InvariantCulture – If you control both the writing and the reading of the file. That way it will work no matter what culture the user has on his computer.
  • CultureInfo.CreateSpecificCulture("en-US") – If you need it to work for a particular culture, independent of the user’s culture.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)