Exception when using ZipArchive

4 posts, 0 answers
  1. Marita
    Marita avatar
    6 posts
    Member since:
    Dec 2013

    Posted 04 Apr 2014 Link to this post

    I have an application where I have been using the following code:

           using (ZipPackage zipPackage = ZipPackage.Open(stream, FileAccess.Read))
                        {
                            foreach (ZipPackageEntry file in zipPackage.ZipPackageEntries.ToList())
                            {
                                if (file.FileNameInZip.Equals("nsData.json"))
                                {
                                    StreamReader streamReader = new StreamReader(file.OpenInputStream());
                                    string jsonString = streamReader.ReadToEnd();
                                }
                           }
                     }

    and it works as expected.

    I have now tried to convert it to using ZipArchive instead, but I am having some problems.

    I use the following code:

      using (ZipArchive archive = new ZipArchive(stream,ZipArchiveMode.Read, false, null))
                        {
                            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();

                            ZipArchiveEntry entry = archive.GetEntry("nsData.json");
                            if (entry != null)
                            {
                                Stream entryStream = entry.Open();
                                StreamReader reader = new StreamReader(entryStream);
                                string content = reader.ReadToEnd();


                            }
                }

    And when it comes to the last line it gives the following exception:

    {Telerik.Windows.Zip.InvalidDataException: Invalid block length
       ved Telerik.Windows.Zip.DeflateDecompressor.DecodeBits()
       ved Telerik.Windows.Zip.DeflateDecompressor.DecodeUncompressedBlock(Boolean& endOfBlock)
       ved Telerik.Windows.Zip.DeflateDecompressor.CheckDecodeState()
       ved Telerik.Windows.Zip.DeflateDecompressor.Decode()
       ved Telerik.Windows.Zip.DeflateDecompressor.Inflate(Byte[] bytes, Int32 offset, Int32 length)
       ved Telerik.Windows.Zip.DeflateDecompressor.ProcessTransform(Boolean finalBlock)
       ved Telerik.Windows.Zip.DeflateTransformBase.TransformBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[] outputBuffer, Int32 outputOffset)
       ved Telerik.Windows.Zip.OperationStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       ved Telerik.Windows.Zip.CompressedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       ved System.IO.StreamReader.ReadBuffer()
       ved System.IO.StreamReader.ReadToEnd()
       ved NstPortalUCSL.ViewModel.ViewModelHandlers.DataSourceHandler.DataSouceHandler.<>c__DisplayClassb.<InitDataSources>b__8(Object sender, GetAllNstInstancesCompletedEventArgs args)
       ved NstPortalUCSL.NstPortalWsSvc.NstPortalWsClient.OnGetAllNstInstancesCompleted(Object state)}


    I would be wery thankfull if you could explain to me what I am doing wrong.

  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 04 Apr 2014 Link to this post

    Hi Marita,

    Could you please clarify which version of Telerik UI for Silverlight you use? I suggest using the 2014 Q1 SP1 version as it contains important fixes in the Zip library.

    Regards,
    Andrey Murzov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Marita
    Marita avatar
    6 posts
    Member since:
    Dec 2013

    Posted 04 Apr 2014 Link to this post

    I use the latest version.
  4. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 04 Apr 2014 Link to this post

    Hi Marita,

    Unfortunately it is impossible to reproduce the problem at least without the zip file you use. Could you, please, provide us with this archive? By doing so we will be able to further investigate the reasons behind the issue.

    Thank you for your cooperation.

    Regards,
    Andrey Murzov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top