Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CsvWriter, CS1503 Argument 2: cannot convert CultureInfo

Tags:

c#

.net

csvhelper

I'm using CsvHelper (great package thanks Josh) and having problems with the constructor with .Net Core when using CultureInfo.

Josh's example has something like this... (from https://joshclose.github.io/CsvHelper/examples/writing/write-class-objects)

   using (var writer = new StreamWriter("path\\to\\file.csv"))
   using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
   {
      csv.WriteRecords(records);
   }

However, that gives me, CS1503 Argument 2: cannot convert from 'System.Globalization.CultureInfo' to 'CsvHelper.Configuration.Configuration'

so, I need to do this instead


using (var writer = new StreamWriter("path\\to\\file.csv"))
using (var csv = new CsvWriter(writer: writer  ))
   {
      csv.Configuration.CultureInfo = CultureInfo.InvariantCulture ; 
      csv.WriteRecords(records);
   }

Is Josh's example wrong or am I doing something wrong ?

like image 479
paul1923 Avatar asked Oct 15 '25 16:10

paul1923


1 Answers

Josh's example works with the current CsvHelper, Version 13.0.0

using (var writer = new StreamWriter("path\\to\\file.csv"))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
   csv.WriteRecords(records);
}

Before Version 13.0.0, your example works.

using (var writer = new StreamWriter("path\\to\\file.csv"))
using (var csv = new CsvWriter(writer))
{
   csv.Configuration.CultureInfo = CultureInfo.InvariantCulture; 
   csv.WriteRecords(records);
}
like image 111
David Specht Avatar answered Oct 18 '25 07:10

David Specht