ZipArchive, 3mf and compression

Stefan

Member
Joined
Jun 1, 2021
Messages
7
Programming Experience
1-3
Hi there,
I have a very weird problem I just can't wrap my head around and not even sure where to ask this.
Basically I'm writing a converter for CAD models to the .3mf file format.
.3mf files are renamed .zip files that have a fixed folder structure and use .xml for their internal data.

I use the official 3mf examples for testing my code and here is the problem:
If I use the windows UI to select the files and rightclick -> 'send to zip archive' everything works correctly.
If I use c# ZipFile or sharpziplib to zip the files - the .3mf throws an error.
If I use tar.exe to zip the files the Windows 3D-viewer throws an error but other CAD programs can open the file.

Hp has a filechecker to look for errors in 3mf files and it throws:
the file is in the archive and is in the right place but for some reason wont be found by the interpreter.

Is there someone that can point me in the right direction?maybe zip files have different was to store path information that is not visible to me as the user?
 
Sure,

code is just this
C#:
string startPath = tempFolderPath;
string zipPath = Path.Combine(_Path, _Filename);
ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, false);

attached the some files zipped by Windows, and zipped by c# ZipFile.
If you rename them to *.3mf you can open them in 3D-Viewer
 

Attachments

  • invalid.zip
    1 KB · Views: 26
  • valid.zip
    1 KB · Views: 24
I can see that the ratio reported by File Explorer is different for a couple of the files so, assuming that they were from the same source, there certainly seems to be a difference in the way they have been compressed. I don't have time to look any deeper right now though.
 
I attached another pair of examples that, to me, look pretty much identical in compression.
I'm really scratching my head here.
 

Attachments

  • invalid.zip
    1 KB · Views: 20
  • valid.zip
    1 KB · Views: 24
Would the order of entries in the package matter?
invalid.zip said:
3D\3dmodel.model
_rels\.rels
[Content_Types].xml
valid.zip said:
[Content_Types].xml
_rels/.rels
3D/3dmodel.model
 
You're both wasting your time with this as it's a problem I have experienced myself, and you're unlikely to resolve the issue. Because i was also unable to resolve when I looked into this previously. The answer is on p1/#3. It has something to do with how the files are compressed, and any change to libraries or compressed files after a file was compressed will likely not be able to decompress. The same applies to files compressed with different compression settings will certainly not be able to decompress with alternative decompressors. These libs are very finicky.
 
I noticed a probably more important difference, the invalid zip has back slashes in entry names, the valid one forward slashes.
Funny thing is when I use ZipFile.CreateFromDirectory the entries get forward slashes. Then I found this:
Starting with apps that target the .NET Framework 4.6.1, the path separator used in the ZipArchiveEntry.FullName property has changed from the backslash ("\") used in previous versions of .NET Framework to a forward slash ("/").
Are you using an old .Net Framework version?
 
I wonder if adding :

C#:
<runtime>
   <AppContextSwitchOverrides value="Switch.System.IO.Compression.ZipFile.UseBackslash=false" />
</runtime>
To the project file would make any difference?

I can't try it, as I don't have those libs, nor do I have my own zip files handy, but you might be onto something here. How on earth is one to know that this "might" be a requirement if working with Zip files on different framework versions? Feck sake Microsoft...

If this works, you will have made this board the only board on the net to provide a solution for this problem. When I was searching around for answers to this, I never found a solution nor worked out the underline issue.
 
Thanks for your help so far guys.
You'll have to take babysteps with me here.

where do I add the
C#:
<runtime>
   <AppContextSwitchOverrides value="Switch.System.IO.Compression.ZipFile.UseBackslash=false" />
</runtime>

in the *.csproj file?
I'm using VS for all of this and targeting .net framework 4.8
 
Last edited:

Latest posts

Back
Top Bottom