Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Offset to Central Directory cannot be held in an Int64

Tags:

c#

For some reason ZipFile.Open started to generate "Offset to Central Directory cannot be held in an Int64". The zip file is valid and the code used to work before.

using (ZipArchive archive = ZipFile.Open(zipFileName, ZipArchiveMode.Read))
like image 969
Dmytro Avatar asked Dec 22 '15 19:12

Dmytro


3 Answers

I too got the same error while running the code, and I tried to open that particular zip file from windows - it didn't open. Tried with 7-zip then also same. Then FTPed the file from the server where I did before and it started working. So I feel that something is wrong with the zip file. Try by using the original zip file from server or check is the zip file is not corrupted.

like image 186
Shan Avatar answered Nov 13 '22 20:11

Shan


There is 1 file inside the archive and it was archived using UNIX gzip

If the archive isn't a ZipFile (.zip), but rather a GZip (.gz) you shouldn't use ZipFile. You should use GZipStream inside the System.IO.Compression namespace.

If it is a .tar.gz (sometimes .tgz) and not a vanilla gzip (.gz) file, you will need to get a 3rd party library to extract it, such as SharpZipLib or SharpCompress.

like image 39
Pete Garafano Avatar answered Nov 13 '22 21:11

Pete Garafano


I had the same error while trying to read the zip content as an Object. Different micro service sends it to my service.

I figured that I used the wrong Deserialize format. I always used UF8 encoding but sometimes I got byte array so UT8 damaged the file. We fixed it by getting a header from the previous micro service that tells me the object type.

Bottom line, make sure you using the right decoder!

like image 2
yohait Avatar answered Nov 13 '22 22:11

yohait