public static string GetWhyCsvIsWrong(RuntimeCsvRepresentation rcr, bool createsDictionary, string fileName) { string duplicateHeader = null; string duplicateRequiredField = null; duplicateHeader = rcr.GetFirstDuplicateHeader; // Check for duplicates ignoring the type if (createsDictionary) { duplicateRequiredField = rcr.FirstDuplicateRequiredField; } if (!string.IsNullOrEmpty(duplicateHeader)) { return("The CSV file " + fileName + "\n\nhas the following duplicate header.\n\n" + duplicateHeader); } else if (createsDictionary && !string.IsNullOrEmpty(duplicateRequiredField)) { return("The CSV file " + fileName + "\n\nhas a duplicate required field:" + duplicateRequiredField); } // WE also have to check for duplicates with different types but the same name List <string> namesFound = new List <string>(); foreach (var header in rcr.Headers) { string name = CsvHeader.GetNameWithoutParentheses(header.OriginalText); if (!string.IsNullOrEmpty(name)) { if (namesFound.Contains(name)) { return("The CSV file " + fileName + " has a duplicate header: " + name); } else { namesFound.Add(name); } } } return(null); }