Everything works fine in debug mode but when we run it in release the ExtractToDirectory call fails.
Here is the function for reference. Just to make sure we are not doing anything weird.
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;
}
Finally, here is the exception we get.
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
A slight changes to Victor's solution. Not linking the SDKs generated an apk that was 53MBs. Too large for the play store's apk size limit.
I set the linking behavior to link SDK assemblies only and it brought the apk size down to 29MBs
Here is the updated window.
@mattewrobbinsdev's suggestion was exactly it. For future readers, here's the dialog in Xamarin Studio:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With