I have a class which models the format of the CSV being uploaded (I'm using the FileHelpers library):
[DelimitedRecord(",")]
public class CSVModel
{
[FieldQuoted('"', QuoteMode.OptionalForBoth, MultilineMode.NotAllow)]
public string Field1;
[FieldQuoted('"', QuoteMode.OptionalForBoth, MultilineMode.NotAllow)]
public string Field2;
}
Then I have a class to display the result of the upload after I've parsed the file row-by-row:
public class UploadResult
{
public List<CSVModel> InvalidField;
public List<CSVModel> Valid;
}
I won't go into detail about how I implement FileHelpers because it all works - a file can be uploaded successfully - it only breaks when I try add an instance of the CSV model to a list like so:
public static UploadResult ProcessCSV(CSVModel[] records)
{
UploadResult uploadResult = new UploadResult();
for (int i = 1; i < records.Length; i++)
{
CSVModel csvModel = records[i];
// check stuff
uploadResult.Valid.Add(csvModel); // this is where it breaks
}
return uploadResult;
}
The exception is giving me nothing more than null reference. What could I be doing incorrectly?
edit: When I debug, 'csvModel' is definitely not null when I try add it to the List
uploadResult.Validnull?