CsvHelper
CsvHelper copied to clipboard
iOS CSV Writing: InvalidOperationException: No public parameterless constructor found.
I saw this come up in a few issues, but I was unable to find any relating to writing a csv. Hopefully this isn't a complete duplicate..
Anyway, I'm writing to csv and it's working on all platforms outside of iOS.
using (StreamWriter writer = new StreamWriter(Application.persistentDataPath + "/output.csv"))
using (CsvWriter csv = new CsvWriter(writer))
{
csv.Configuration.RegisterClassMap<MyClass.MyClassMap>();
csv.WriteRecords(_myclass.MyClass as IEnumerable);
}
Is there an alternative way to write to CSV, identical to how I am above? I have not been able to find a workaround, but I'm sure I'm missing something obvious.
You can't use WriteRecords
, WriteRecord
, GetRecords
or GetRecord
because they use System.Linq.Expressions
, which iOS doesn't allow. You'll need to loop the records and do csv.WriteField(obj.Property)
.
It looks like there is a new Expression<TDelegate>.Compile(bool)
that may allow for this. https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expression-1.compile?view=netframework-4.7.2#System_Linq_Expressions_Expression_1_Compile_System_Boolean_
I'll have to look into that a little more and see if this will allow for this in iOS now.
Looks like dotnet might just do it for you. https://stackoverflow.com/a/42033899/68499
Are you using the netstandard version of CsvHelper?
I'm running off the Unity build, so I'm a little limited here.
Off the Unity build of CsvHelper?
You can't use
WriteRecords
,WriteRecord
,GetRecords
orGetRecord
because they useSystem.Linq.Expressions
, which iOS doesn't allow. You'll need to loop the records and docsv.WriteField(obj.Property)
.It looks like there is a new
Expression<TDelegate>.Compile(bool)
that may allow for this. https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expression-1.compile?view=netframework-4.7.2#System_Linq_Expressions_Expression_1_Compile_System_Boolean_I'll have to look into that a little more and see if this will allow for this in iOS now.
Does it support on ios now? It seems .net 8 support linq, but i got this issue