Xamarin Android:System.IO.Compression.ZipFile.ExtractToDirectory在发布模式下失败

时间:2015-07-14 23:31:43

标签: c# android xamarin

在调试模式下一切正常,但是当我们在发布时运行它时,ExtractToDirectory调用失败。

以下是供参考的功能。只是为了确保我们没有做任何奇怪的事情。

private bool UnzipFiles()
    {
        bool toReturn = true;
        try
        {
            UpdateStatus("Almost done...");
            string file = Path.Combine (DownloadFolder, "ZipFile.zip");
            if(System.IO.Directory.Exists(UnzippingDestinationFolder))
            {
                System.IO.Directory.Delete(UnzippingDestinationFolder, recursive:true);
            }

            System.IO.Compression.ZipFile.ExtractToDirectory(file, UnzippingDestinationFolder);
            UpdateStatus("Finished!");
            var files = System.IO.Directory.GetFiles(UnzippingDestinationFolder);

            int m = 3;

        }
        catch (Exception e)
        {
            toReturn = false;
        }

最后,这是我们得到的例外。

System.NullReferenceException: Object reference not set to an instance of an object
  at SharpCompress.Common.Zip.Headers.ZipFileEntry.DecodeString (System.Byte[] str) [0x00000] in <filename unknown>:0 
  at SharpCompress.Common.Zip.Headers.DirectoryEntryHeader.Read (System.IO.BinaryReader reader) [0x00000] in <filename unknown>:0 
  at SharpCompress.Common.Zip.ZipHeaderFactory.ReadHeader (UInt32 headerBytes, System.IO.BinaryReader reader) [0x00000] in <filename unknown>:0 
  at SharpCompress.Common.Zip.SeekableZipHeaderFactory+<ReadSeekableHeader>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0 
  at SharpCompress.Archive.Zip.ZipArchive+<LoadEntries>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0 
  at SharpCompress.LazyReadOnlyCollection`1+LazyLoader[SharpCompress.Archive.Zip.ZipArchiveEntry].MoveNext () [0x00000] in <filename unknown>:0 
  at System.IO.Compression.ZipArchive.CreateZip (System.IO.Stream stream, ZipArchiveMode mode) [0x00000] in <filename unknown>:0 
  at System.IO.Compression.ZipArchive..ctor (System.IO.Stream stream, ZipArchiveMode mode, Boolean leaveOpen, System.Text.Encoding entryNameEncoding) [0x00000] in <filename unknown>:0 
  at System.IO.Compression.ZipFile.Open (System.String archiveFileName, ZipArchiveMode mode, System.Text.Encoding entryNameEncoding) [0x00000] in <filename unknown>:0 
  at System.IO.Compression.ZipFile.ExtractToDirectory (System.String sourceArchiveFileName, System.String destinationDirectoryName, System.Text.Encoding entryNameEncoding) [0x00000] in <filename unknown>:0 
  at System.IO.Compression.ZipFile.ExtractToDirectory (System.String sourceArchiveFileName, System.String destinationDirectoryName) [0x00000] in <filename unknown>:0 
  at NewBaron.Screens.DownloadContentScreen.UnzipFiles () [0x00000] in <filename unknown>:0 

2 个答案:

答案 0 :(得分:5)

Victor的解决方案略有变化。没有链接SDK生成了一个53MB的apk。对于Play商店的apk大小限制来说太大了。

我将链接行为设置为仅链接SDK程序集,并将apk大小降至29MB

这是更新后的窗口。

enter image description here

答案 1 :(得分:1)

@ mattewrobbinsdev的建议正是如此。对于未来的读者,这是Xamarin Studio中的对话框:

Dialog