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.

ZipArchive.TestArchive(true) fails after using IO.Compression.ZipFile.CreateFromDirectory() on an Folder with several small textfiles

See original GitHub issue

Steps to reproduce

  1. Use the files in the attached zip to create an zip file using ZipFile.CreateFromDirectory() from the namespace System.Io.Compression.
  2. Create a new ZipArchive-Object and test it using TestArchive. ZipFile zipFile = new ZipFile(pathToZipFile); bool success = zipFile.TestArchive(true); zipFile.Close();
  3. Check the return value.

Expected behavior

The return value should be true because it is a proper archive file.

Actual behavior

The return value is always false.

It turns out that, if I use SharpZibLib to generate the archive (which is not an option for the problem I’m working on), TestArchive returns true. It also succeeds, if I only put an database file of the size of ~500kb into the archive. But if I then add File1.txt and Subfolder1\Subfile2.txt (from Testfiles.zip), it returns false again.

Version of SharpZipLib

v1.1.0.145

Obtained from (only keep the relevant lines)

  • Package installed using NuGet

Testfiles.zip

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Kalkihecommented, Jan 5, 2022

Thanks for your hint. I took another look and realized, I took the wrong version. Actually, I’m using version 1.1.0.145, which obviously is quiet outdated. In that project, it isn’t referenced as nuget paket as I first thought, so I’m going to fix that issue.

I tried it out in a new project using the current nuget package alongside the same data. This works pretty well, so updating the package should solve the issue.

Thanks for your help.

0reactions
pikselcommented, Jan 5, 2022

You can get the errors by supplying a logging callback to the method:

new ZipFile(archiveStream).TestArchive(true, TestStrategy.FindAllErrors, (status, message) =>
{
    if (status.Operation == TestOperation.EntryData) return;
    var pad = "";
    if (status.Entry is { } entry)
    {
        PrettyConsole.WriteLine($"[{status.Operation}{pad}] #{entry.ZipFileIndex} {entry.Name}");
    }
    else
    {
        PrettyConsole.WriteLine($"[{status.Operation}{pad}]");
    }

    if (!string.IsNullOrEmpty(message))
    {
        PrettyConsole.WriteLine($"[{status.Operation}{pad}] {message}");
    }
});

(this is from the tests done in ArchiveDiag, which actually returns true for the file).

Version of SharpZipLib v4.0.30319

That’s not an official SharpZipLib version… maybe you are using a fork?

Read more comments on GitHub >

github_iconTop Results From Across the Web

.net - c# ZipFile.CreateFromDirectory - the process cannot ...
The zip file is trying to zip all of the contents of the folder, but is written while still reading the folder. This...
Read more >
ZipFile.CreateFromDirectory Method
This example shows how to create and extract a zip archive by using the ZipFile class. It compresses the contents of a folder...
Read more >
Can you zip a file from the command prompt using ONLY ...
Run this in a command-line window to create a ZIP file named C:\someArchive.zip containing all files in folder C:\test3 :
Read more >
Creating Zip Files Easily in .NET 4.5
We will use the updated System.IO.Compression namespace to easily create, update, and extract zip files.
Read more >
System.IO - John Nelson's Blog
FileSystem assembly. The following little walkthrough will allow us to use the methods of the ZipFile class to work with a simple zip...
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