You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a list of string arrays that I want to write to a csv file, but I keep getting an error on csv.WriteRecords() or csv.WriteRecord()
CsvHelper.Configuration.ConfigurationException
HResult=0x80131500
Message=Types that inherit IEnumerable cannot be auto mapped. Did you accidentally call GetRecord or WriteRecord which acts on a single record instead of calling GetRecords or WriteRecords which acts on a list of records?
Source=CsvHelper
StackTrace:
at CsvHelper.Configuration.ClassMap.AutoMap(CsvContext context)
at CsvHelper.CsvContext.AutoMap(Type type)
at CsvHelper.CsvWriter.WriteHeader(Type type)
at CsvHelper.CsvWriter.WriteHeaderFromTypeT
at CsvHelper.CsvWriter.WriteRecords[T](IEnumerable`1 records)
This is an example of what I am doing:
void Main()
{
var input = new List<string[]>()
{
new string[] { "a1", "a2" },
new string[] { "b1", "b2" },
new string[] { "c1", "c2" }
};
using (var writer = new StreamWriter(outputFile))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv.WriteRecords(input);
}
}
I've also tried
using (var writer = new StreamWriter(outputFile))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
foreach (var row in input)
{
csv.WriteRecord(row);
}
}
Am I using WriteRecord()/WriteRecords() incorrectly? Thanks
The text was updated successfully, but these errors were encountered:
CsvHelper is expecting an object with members to map rather than an array of strings. I believe the only way to do it would be to have CsvHelper write out the individual fields.
See #765
voidMain(){varinput=newList<string[]>(){newstring[]{"a1","a2"},newstring[]{"b1","b2"},newstring[]{"c1","c2"}};//using (var writer = new StreamWriter(Console.Out))using(varcsv=new CsvWriter(Console.Out, CultureInfo.InvariantCulture)){foreach(var row in input){foreach(var item in row){
csv.WriteField(item);}
csv.NextRecord();}}}
Contrary to what the name implies, it seems to works with string[], and doesn't require string
using (var writer = new StreamWriter(outputFile))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
foreach (var row in input)
{
csv.WriteField(row);
}
}
Hi,
I am using CsvHelper 33.0.1
I have a list of string arrays that I want to write to a csv file, but I keep getting an error on csv.WriteRecords() or csv.WriteRecord()
This is an example of what I am doing:
I've also tried
Am I using WriteRecord()/WriteRecords() incorrectly? Thanks
The text was updated successfully, but these errors were encountered: