diff --git a/FileHelpers/MultiRecord/MultiRecordEngine.cs b/FileHelpers/MultiRecord/MultiRecordEngine.cs index ef374c5e..d2e3431f 100644 --- a/FileHelpers/MultiRecord/MultiRecordEngine.cs +++ b/FileHelpers/MultiRecord/MultiRecordEngine.cs @@ -174,17 +174,15 @@ public object[] ReadStream(IRecordReader reader) { mReader = freader }; - while (currentLine != null) { + Type currentType = null; try { mTotalRecords++; currentRecord++; line.ReLoad(currentLine); - - Type currentType; try { currentType = mRecordSelector(this, currentLine); @@ -225,7 +223,7 @@ public object[] ReadStream(IRecordReader reader) mLineNumber = freader.LineNumber, mExceptionInfo = ex, mRecordString = completeLine, - mRecordTypeName = RecordInfo.RecordType.Name + mRecordTypeName = currentType?.Name }; mErrorManager.AddError(err); @@ -577,25 +575,26 @@ private void ReadNextRecord() { mReader = mAsyncReader }; - + while (true) { + Type currentType = null; if (currentLine != null) { try { mTotalRecords++; - Type currType = mRecordSelector(this, currentLine); + currentType = mRecordSelector(this, currentLine); line.ReLoad(currentLine); - if (currType != null) + if (currentType != null) { - mRecordInfoTable.TryGetValue(currType, out IRecordInfo info); + mRecordInfoTable.TryGetValue(currentType, out IRecordInfo info); if (info == null) { - throw new BadUsageException("A record is of type '" + currType.Name + + throw new BadUsageException("A record is of type '" + currentType.Name + "' which this engine is not configured to handle. Try adding this type to the constructor."); } @@ -622,7 +621,7 @@ private void ReadNextRecord() mLineNumber = mAsyncReader.LineNumber, mExceptionInfo = ex, mRecordString = currentLine, - mRecordTypeName = RecordInfo.RecordType.Name + mRecordTypeName = currentType?.Name }; mErrorManager.AddError(err);