"Buffer size is less than minimum BIFF record size" error even with cs 82970 and Loose option

Oct 4, 2013 at 4:18 PM
I got this exception with an xls file and added the ReadOption.Loose parameter but still get the exception.

It occurs after successfully reading all the rows of this file so I updated the code to continue after the exception is caught and the specific error occurred and there was data in the stringbuilder collecting the rows. Also, I display a message to the user to verify the import worked as expected.

Gary Davis
Oct 18, 2013 at 11:18 PM
Hello. I had the same issue. Happened near the end of the file read with the data already captured. File is a SRS output xls file.

Quick fix for me for this file at least was the following:

Had comment out the check here: XlsBiffRecord.cs line 19
protected XlsBiffRecord(byte[] bytes, uint offset, ExcelBinaryReader reader)
            //if (bytes.Length - offset < 4)
                //throw new ArgumentException(Errors.ErrorBIFFRecordSize);
            m_bytes = bytes;
            this.reader = reader;
            m_readoffset = (int)(4 + offset);

            //Set readOption to loose to not cause exception here (sql reporting services)
            if (reader.ReadOption == ReadOption.Strict)
                if (bytes.Length < offset + Size)
                    throw new ArgumentException(Errors.ErrorBIFFBufferSize);
And add the try/catch here XlsBiffRecord.cs line 52
        /// <summary>
        /// Returns data size of this entry
        /// </summary>
        public ushort RecordSize
                // Added Try Catch block in case of badly formed SQL reporting file with < 4 
                    return BitConverter.ToUInt16(m_bytes, m_readoffset - 2);
                    return BitConverter.ToUInt16(m_bytes, m_readoffset - 3);