question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ExcelReaderFactory.CreateReader throwing exception for End of Central Directory mismatch when called with a MemoryStream

See original GitHub issue

Given the following:

private static void diffZipArchiveEntry(ZipArchiveEntry zipArchiveEntry1, ZipArchiveEntry zipArchiveEntry2)
{
    using (var stream1 = zipArchiveEntry1.Open())
    using (var stream2 = zipArchiveEntry2.Open())
    using (var xlsxReader1 = ExcelReaderFactory.CreateReader(stream1))
    using (var xlsxReader2 = ExcelReaderFactory.CreateReader(stream2))
    {
        // compare the two streams
    }
}

A System.NotSupportedException is thrown on the factory method. Just wanted to see if this intentional or not and whether I have to hit the disk and extract these .zip files before comparing the .xlsx inside them or whether it’s another issue entirely.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
andersnmcommented, Mar 26, 2018

Hi,

ExcelDataReader requires a seekable stream as input, and after verifying with a little program, it appears ZipArchiveEntry.Open() does not return a seekable stream.

To avoid the disk, there’s also an option to extract into a MemoryStream and pass that to the ExcelReaderFactory, if appropriate for your use case.

            var zip = System.IO.Compression.ZipFile.OpenRead("..\\..\\test.zip");
            var entry = zip.Entries[0];
            var stream = entry.Open();
            Console.WriteLine("Can seek: " + stream.CanSeek.ToString());

            // Output:
            // Can seek: False
0reactions
ateccecommented, Mar 27, 2018

Rofl. Looks like I tried to load the same stream into a memory stream twice. Thanks for all your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid Data Exception when using ExcelDataReader
End of Central Directory record could not be found. The Exception occurs from the second time I call the function. What Can Be...
Read more >
WinZip error - central and local directory mismatch
A zip file is structured to have file headers preceding each file entry, followed at the end by a central directory. The central...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found