Migration guide
Migrating to v21.0.0
Moving to v21.0.0 from v20.0.0. Changelog.
CsvHelper 21 has one breaking change: CsvConfiguration.NewLine is a string instead of a char?. You can now write
any line ending, including \r\n, which 20 could only write where it is Environment.NewLine. When you set it, the
parser uses it too, in every mode. The NewLine enum and the NewLines constants, unused since 20, are removed. The
target frameworks don't change.
Line endings
Give NewLine a string instead of a character.
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
NewLine = '\n',
};var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
NewLine = "\n",
};| CsvHelper 20 | CsvHelper 21 | Notes |
|---|---|---|
NewLine = '\n' |
NewLine = "\n" |
|
NewLine = '\r' |
NewLine = "\r" |
|
NewLine = null |
Leave it unset | Setting null counts as setting it: creating the parser then throws, and so does writing a non-empty field with the default ShouldQuote. |
| none | NewLine = "\r\n" |
|
NewLines.CRLF, NewLines.CR, NewLines.LF |
"\r\n", "\r", "\n" |
The NewLines class is removed. |
- The default when writing: 21.0.0 writes
Environment.NewLine, as 20 did. 21.0.2 and later write\r\n. IsNewLineSetis new: it tells whetherNewLinewas set or is the default. If you implementIParserConfigurationorIWriterConfiguration, changeNewLineto astringand addIsNewLineSet.
Behavior changes
- A
NewLineyou set is used for reading too, in every mode. In 20, the default mode ignored it and ended a record at\r\n,\ror\n. In 21, onlyNewLineends a record. If you setNewLine = "\n"to write files and read with the same configuration, a file with\r\nline endings keeps the\rat the end of the last field of each record (or, when that field is quoted, it is bad data). Read with a configuration that doesn't setNewLine. - The Visual Basic constructor that 21.0.5 adds, with every setting as an optional argument, sets
NewLineeven when you don't pass it, so a configuration created with it reads only\r\nas a line ending. 22.1.1 fixes this. ParserMode.EscapewithoutNewLineends a record at\r\n,\ror\n. In 20 it used\nby default. Before 21.1.1, it reads\r\nas\rfollowed by a blank line, whichIgnoreBlankLines(on by default) skips.- Quoting: the default
ShouldQuotequotes a field that contains\ror\nwhenNewLineisn't set, and a field that containsNewLinewhen it is.
All API changes
Every change to the public API since v20.0.0: 3 added, 3 changed, 2 removed (5 breaking). Open a type to see its changes.
CsvConfigurationrecord1 breaking1 changed1 added
NewLineBreaking
The type changed from char? to string.
public virtual char? NewLine { get; init; }public virtual string NewLine { get; init; }Added
IParserConfigurationinterface1 breaking1 changed1 added
NewLineBreaking
The type changed from char? to string.
char? NewLine { get; }string NewLine { get; }Added
IWriterConfigurationinterface1 breaking1 changed1 added
NewLineBreaking
The type changed from char? to string.
char? NewLine { get; }string NewLine { get; }Added
Removed types (2)