Can the FileHelpers library write classes that contain fields with a null value and also read them?

I am using version 2.0 of the FileHelpers library, which is documented as capable of handling .NET.NET Nullable types.

I use the code shown in the example from the documentation:

[DelimitedRecord("|")]   
public class Orders   
{   
    public int OrderID;   

    public DateTime? OrderDate;   

    [FieldConverter(ConverterKind.Date, "ddMMyyyy")]     
    public DateTime? RequiredDate;   

    public int? ShipVia;   
}   

With FileHelperEngine, I can successfully read in a file that does not matter for the OrderDate, RequiredDate, or ShipVia fields. The file looks like this:

1 |||

However, I cannot then write the resulting Orders [] to a file - the library throws the following: NullReferenceException, the stack trace below:

FileHelpers.ConvertHelpers.CultureConverter.FieldToString(Object from)   FileHelpers.FieldBase.BaseFieldString(Object fieldValue)   FileHelpers.DelimitedField.CreateFieldString(StringBuilder sb, Object fieldValue)   FileHelpers.FieldBase.AssignToString(StringBuilder sb, Object fieldValue)   FileHelpers.RecordInfo.RecordToString( )   FileHelpers.FileHelperEngine 1.WriteStream(TextWriter writer, IEnumerable 1 , Int32 maxRecords)   FileHelpers.FileHelperEngine 1.WriteFile(String fileName, IEnumerable 1 , Int32 maxRecords)   FileHelpers.FileHelperEngine 1.WriteFile(String fileName, IEnumerable 1 )   TestingFileHelpers.Program.Main(String [] args) C:\dev\src\TestingFileHelpers\TestingFileHelpers\Program.cs: 19   System.AppDomain._nExecuteAssembly ( RuntimeAssembly, String [] args)   System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String [] args)   Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()   System.Threading.ThreadHelper.ThreadStart_Context ( )   System.Threading.ExecutionContext.Run(ExecutionContext executeContext, ContextCallback, , Boolean ignoreSyncCtx)   System.Threading.ExecutionContext.Run(ExecutionContext executeContext, ContextCallback, )   System.Threading.ThreadHelper.ThreadStart()

, , , - , , . .

+5
2

[FieldNullValue("")], .

0

All Articles