SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

SharpZipLib cannot compress ICSharpCode.SharpZipLib.dll

Last post 11-16-2012 12:39 AM by jerrydrake. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 04-11-2011 5:29 PM

    • SFun28
    • Not Ranked
    • Joined on 04-11-2011
    • Posts 2

    SharpZipLib cannot compress ICSharpCode.SharpZipLib.dll

    This seems bitterly ironic, and hope I don't make a fool of myself in this first post to the community.

    When I try to compress ICSharpCode.SharpZipLib.dll I get the following exception:

    ICSharpCode.SharpZipLib.Zip.ZipException: Entry size/stream size mismatch

    1. This happens even when I apply the following fix: http://bugtracker.sharpdevelop.net/issue/ViewIssue.aspx?id=1724&PROJID=2
    2.  I'm not trying to compress the loaded assembly...this is just another copy of the assembly
    3. If I change the file name to extension .txt it works fine
    4. If I remove the strong name key from the assembly and apply my own key it works fine 

    Here's the code I'm using to compress:

    public static void CompressFile( string sourceFilePath , string zipFilePath )
            {
                ZipFile zip = ZipFile.Create( zipFilePath );
                zip.BeginUpdate();
                zip.Add( sourceFilePath , Path.GetFileName( sourceFilePath ) );
                try
                {
                    zip.CommitUpdate();
                    zip.Close();
                }
                catch ( Exception )
                {
                    Log.Info( "Failed to compress file " + sourceFilePath + " to file " + zipFilePath );
                    zip.AbortUpdate();
                    zip.Close();  // we have to close before deleting, otherwise SharpZipLib maintains a lock.
                    File.Delete( zipFilePath );
                    throw;
                }
                
            }
    
    
    Relevant stack trace:
       at ICSharpCode.SharpZipLib.Zip.ZipFile.AddEntry(ZipFile workFile, ZipUpdate update)
       at ICSharpCode.SharpZipLib.Zip.ZipFile.RunUpdates()
       at ICSharpCode.SharpZipLib.Zip.ZipFile.CommitUpdate()
  • 04-21-2011 2:04 AM In reply to

    Re: SharpZipLib cannot compress ICSharpCode.SharpZipLib.dll

    Hi,

    Wow. This is the weirdest thing I have seen reported in, as long as i can recall. Happens to me too. Good analysis there on what fixes it and what makes no difference.

    Oddest of all perhaps ... "If I change the file name to extension .txt it works fine"

    Will look into it.

    Thanks!

    Dave

  • 04-21-2011 5:32 AM In reply to

    Re: SharpZipLib cannot compress ICSharpCode.SharpZipLib.dll

    Okay, ironically this is essentially the same bug as this one ...

    http://bugtracker.sharpdevelop.net/issue/ViewIssue.aspx?id=1684&PROJID=2
    "File TimeStamp is lost via ZipFile.Add with modified entryname"

    The bug happens because it finds a file of the same name ("ICSharpCode.SharpZipLib.dll") in the assembly folder and uses its length instead.

    I will update that bugtracker to point to this thread as well.

    Thanks for the heads up!

    Dave

  • 04-28-2011 4:58 AM In reply to

    • SFun28
    • Not Ranked
    • Joined on 04-11-2011
    • Posts 2

    Re: SharpZipLib cannot compress ICSharpCode.SharpZipLib.dll

    Thanks, Dave!  I seriously thought I was going crazy. =)

  • 11-16-2012 12:05 AM In reply to

    Re: SharpZipLib cannot compress ICSharpCode.SharpZipLib.dll

    Hi Dave, I still got this problem in version 0.86.0.518. Can you give me a workaround?

     

    thanks

    walter

  • 11-16-2012 12:15 AM In reply to

    Re: SharpZipLib cannot compress ICSharpCode.SharpZipLib.dll

    Hi Walter,

    Would help to know what is the use case, What is your software doing, that you are updating a zip file with the SharpZipLib dll?

    thanks
    David

  • 11-16-2012 12:39 AM In reply to

    Re: SharpZipLib cannot compress ICSharpCode.SharpZipLib.dll

    the following...

     

    Okay, ironically this is essentially the same bug as this one ...

    http://bugtracker.sharpdevelop.net/issue/ViewIssue.aspx?id=1684&PROJID=2
    "File TimeStamp is lost via ZipFile.Add with modified entryname"

    The bug happens because it finds a file of the same name ("ICSharpCode.SharpZipLib.dll") in the assembly folder and uses its length instead.

    I will update that bugtracker to point to this thread as well.

    Thanks for the heads up!

    Dave

     

    this is my code with a workaround that solves (I got it meanwhile), look for the word "WORKAROUND" to understand my solution:

    public bool Zip(string zipFullFilename, Collection fileList, bool keepFolderNames = false, bool deleteFilesAfterZip = false)

    {

    bool result = false;

    string entryFullFilename = "";

    string entryFilename = "";

    ZipFile zipManager = null;


                // WORKAROUND PER RAGGIRARE IL BUG DI QUANDO SI ZIPPA UN FILE

                // IN UN ALTRA CARTELLA MA CHE HA UN OMONIMO NELLA CARTELLA

                // DELL'APPLICAZIONE

                string currentDirectory = Directory.GetCurrentDirectory();


    try 

                {

    // nome completo del file zip da creare

    _ZipFullFilename = zipFullFilename;


    // ellimino in caso di esistenza

    if (System.IO.File.Exists(_ZipFullFilename)) System.IO.File.Delete(_ZipFullFilename);


    // gestore del file zip

    zipManager = ICSharpCode.SharpZipLib.Zip.ZipFile.Create(_ZipFullFilename);


    //'SyncLock zipManager

    //'End SyncLock

    if (InitializeWaitForm != null)  InitializeWaitForm();

    if (InitializeBar1 != null) InitializeBar1(1);

    if (InitializeBar2 != null) InitializeBar2(fileList.Count);

    if (IncrementBar1 != null) IncrementBar1("", "");


    // processo tutti i file della collection

    // includo anche il percorso del file

    if (keepFolderNames) 

                    {

    foreach (string entryFullFilename_loopVariable in fileList) 

                        {

    entryFullFilename = entryFullFilename_loopVariable;

    if (IncrementBar2 != null) IncrementBar2(entryFullFilename);


    // mi accerto che il file esista sempre

    if (!System.IO.File.Exists(entryFullFilename)) continue;


    zipManager.BeginUpdate();

    zipManager.Add(entryFullFilename, CompressionMethod.Deflated, true);

    zipManager.CommitUpdate();

    }

                    else 

                    {

                        foreach (string entryFullFilename_loopVariable in fileList) 

                        {

    entryFullFilename = entryFullFilename_loopVariable;

    if (IncrementBar2 != null) IncrementBar2(entryFullFilename);


    // mi accerto che il file esista sempre

    if (!System.IO.File.Exists(entryFullFilename)) continue;


    entryFilename = entryFullFilename.Substring(entryFullFilename.LastIndexOf("\\") + 1);


                            System.Threading.Thread.Sleep(500);


                            // WORKAROUND

                            Directory.SetCurrentDirectory(entryFullFilename.Substring(0, entryFullFilename.LastIndexOf("\\"))); 


    zipManager.BeginUpdate();

                            zipManager.Add(entryFullFilename, entryFilename);

    zipManager.CommitUpdate();

    }

    }


    // verifico se devo eliminare i file e/0 le cartelle

    if (deleteFilesAfterZip) CleanFiles(fileList);


    result = true;

                catch (System.Exception ex) 

                {

                    General.DisplayException(ex, "ZipManager.Zip", "entryFlename =" + entryFilename, 

                                                 "fullFilename =" + entryFullFilename,

                                                 "_ZipFullFilename =" + _ZipFullFilename);

    }


                // WORKAROUND

                Directory.SetCurrentDirectory(currentDirectory); 


    if (zipManager != null) {

    zipManager.Close();

    zipManager = null;

    }


    if (DisposeWaitForm != null) {

    DisposeWaitForm();

    }


    return result;

    }

     

     

Page 1 of 1 (7 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.