'List with several results in it needs to go to another list for output to csv
I have one list that is called SearchResult the model for it looks like this:
public class Wrapper
{
public Wrapper()
{
Columns = new List<SearchColumn>();
Rows = new List<SearchRow>()
}
public long Total { get; set; } = 0;
public double Milliseconds { get; set; }
public List<SearchColumn> Columns { get; set; }
public List<SearchRow> Rows { get; set; }
}
I use this in a method to attempt to return the result set and export it to a csv file like this:
private Wrapper SearchResult { get; set; } = new();
public async Task<DownloadFile> StartExport()
{
//code removed for brevity
var searchComp = 10000;
var fileName = "SearchResults";
var records = SearchResult.Rows.ToList();
if (defaultValue <= searchComp)
{
await Task.Yield();
return fileEx.ExportToCsv(records, fileName);
}
}
This builds and runs in the application but still does not produce a csv file with the information on it.
The error that I get is "System.NullReferenceException: Object reference not set to an instance of an object"
At this line:
return fileEx.ExportToCsv(records, fileName);
I assumed it was the "records" returning null however when I debugged the code records had information in it.
So why wouldn't it produce the csv file? I also debugged the ExportToCsv method with a file I knew worked and it worked as expected.
This should return: ID, Name, DOB... in a csv file.
What should I do to remedy the error I am getting?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
