Strange ZIP corruption when adding to archive one by one

Mar 15, 2014 at 3:47 AM
Edited Mar 15, 2014 at 4:23 AM
DotNetZip v1.9.1.8, .NET4, Win8.1, Desktop App.

I am adding around 10 files one at a time by calling the function below, saving the ZIP when every file is added. For some reason the larger (8MB or so) file gets corrupted when I unzip it with DotNetZip and 7zip. No errors are reported during the compression. Testing the ZIP in 7zip reports a CRC error.

Antivirus software is just Windows Defender.
If I use 7zip to create the same archive there is no corruption.
All files are on local HDD's.

        public static bool AddFile(string sZIPFile, string sFileToAdd, string sNameInArchive, string sPassword = null)
        {
            try
            {
                // File exists?
                if(File.Exists(sZIPFile))
                {
                    // Remove existing
                    using (ZipFile zip = ZipFile.Read(sZIPFile))
                    {
                        if(String.IsNullOrEmpty(sPassword)==false) zip.Password = sPassword;
                        //zip[sNameInArchive].FileName = null;
                        zip.RemoveEntry(sNameInArchive);
                        zip.Save();
                    }   
                }
                else
                {
                    // Create new ZIP
                    ZipFile zip = new ZipFile(sZIPFile);
                    zip.Save();
                }
            }
            catch(Exception)
            {}
            
                
            try
            {
                // Get just the filename
                string sAddFileName = Path.GetFileName(sFileToAdd);
            
                // Add file to zip
                using (ZipFile zip = ZipFile.Read(sZIPFile))
                {

                    
                    // update
                    if(String.IsNullOrEmpty(sPassword)==false) zip.Password = sPassword;
                    
                    zip.UpdateItem(sFileToAdd,"");
                    zip[sAddFileName].FileName = sNameInArchive;
                    //zip[sAddFileName].Comment = 
                    

                    // add a comment to the archive
                    //zip.Comment = 
                    zip.Save();
                }
                

            }
            catch(Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("ZipHelper AddFile Exception: "+ex.Message);
                return false;
            }
                
            return true;
        }       
Loop code calling the AddFile function above

        string[] sFiles = Directory.GetFiles(sBase+sFolderName);

        foreach(string sFile in sFiles)
        {
            bool bret = ZipHelper.AddFile(sZIP, sFile, Path.GetFileName(sFile), null);
            if(bret==false) ErrMsg("AddZip Failed "+sFile);
        }