Skip to content

Conversation

@himanshugupta-mt
Copy link

@himanshugupta-mt himanshugupta-mt commented Jun 16, 2017

The issue I encountered was the object defined like

class Product
{
        [CsvColumn(Name = "A")]
	public int A { get; set; }
        [CsvColumn(Name = "B" ,CanBeNull = false)]
	public string B { get; set; }
	[CsvColumn(Name = "C", CanBeNull = false)]
	public string C { get; set; }
}

CsvFileDescription inputFileDescription = new CsvFileDescription
{
      SeparatorChar = ',',
      FirstLineHasColumnNames = true,
      EnforceCsvColumnAttribute = true
};

CsvContext cc = new CsvContext();
IEnumerable<Product> products = cc.Read<Product>("a.csv", inputFileDescription);


and a.csv looks like this

B,C
b,c

The library does not handle this case correctly. It still complains that the value of Column C is not provided.

@tonyjunio
Copy link

Hi! I've been trying to look for this solution. I thought the index error will be fixed by IgnoreUnknownColumns but turned out the error is because my model has more fields than the csv.

My scenario is this. I defined one model class with all possible fields because my csv report files, although they are of the same report type, can have different available columns.

Anyhoo, I will try this updates you have. Many thanks! ^__^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants