CsvHelper.Excel
CsvHelper.Excel copied to clipboard
MissingMethodException set_LeaveOpen
Trying to use ExcelWriter.WriteRecords and I get:
System.MissingMethodException: Method not found: 'Void CsvHelper.Configuration.CsvConfiguration.set_LeaveOpen(Boolean)'. at CsvHelper.Excel.ExcelWriter..ctor(Stream stream, String sheetName, CultureInfo culture, Boolean leaveOpen)
Versions (please complete the following information):
- CSVHelper: 27.0.2
- CSVHelper.Excel.Core: 22.1.1
I am facing the same issue; quick and dirty (well, very dirty) "solution" to get it going on my end by using reflection:
var records = new List<ReportRecord>();
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
NewLine = Environment.NewLine,
Encoding = Encoding.UTF8,
LeaveOpen = true // very important, or MemoryStream will be disposed
};
await using var ms = new MemoryStream();
// use private constructor to bypass faulty line
await using (var excelWriter = (ExcelWriter) Activator.CreateInstance(
typeof(ExcelWriter),
BindingFlags.Instance | BindingFlags.NonPublic,
null,
new object[] {ms, "activity_report_last14days", config},
null,
null
))
{
excelWriter.Context.RegisterClassMap<ReportRecordMap>();
await excelWriter.WriteRecordsAsync(records);
}
ms.Seek(0, SeekOrigin.Begin);
// use stream for whatever purpose
Disclaimer: this will most probably blow up sooner or later but I needed a working solution quickly 😅
Cheers
@nefarius, @altmank Can you see if your issue is resolved? There was a change to leaveOpen
Released
I currently have no active project I could test it with but judging by the changelog it should be good, thanks! Maybe @altmank can test it 😃