You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
This issue has been moved from
a ticket on Developer Community
.
I reported
https://developercommunity.visualstudio.com/t/Apps-crashing-when-using-ZipFileCreateF/1651269?space=61&ftype=problem&preview2=true&q=CreateFromDirectory&sort=newest
back in January,
During my summer vacation Microsoft support asked for some extra info, but that request did not reach me as I was away. Anyway, here is the info as requested.
In our application customers are experiencing crashes when ZipFile.CreateFromDirectory. To me it appears, as that function does not clean itself properly in case of failure, and then GarbageCollector experiences an exception, leading to crash.
In January, the crash occurred when creating the zip file to a network drive with aforementioned function. Now I've noticed that the same (similar) thing occurs also, when the target drive is a USB stick, that is almost full, so that during the execution of the function the drive becomes full.
In January, I was using VS 2019 with .Net Framework 4.7.1, now I've switched to .Net 4.8. As far as I can tell, my Visual studio is up-to-date with updates.
Original Comments
Feedback Bot on 8/30/2022, 01:03 AM:
(private comment, text removed)
Dan Moseley [MSFT] on 11/8/2022, 09:10 PM:
(private comment, text removed)
Original Solutions
(no solutions)
Tagging subscribers to this area: @dotnet/area-system-io-compression
See info in
area-owners.md
if you want to be subscribed.
Issue Details
This issue has been moved from
a ticket on Developer Community
.
I reported
https://developercommunity.visualstudio.com/t/Apps-crashing-when-using-ZipFileCreateF/1651269?space=61&ftype=problem&preview2=true&q=CreateFromDirectory&sort=newest
back in January,
During my summer vacation Microsoft support asked for some extra info, but that request did not reach me as I was away. Anyway, here is the info as requested.
In our application customers are experiencing crashes when ZipFile.CreateFromDirectory. To me it appears, as that function does not clean itself properly in case of failure, and then GarbageCollector experiences an exception, leading to crash.
In January, the crash occurred when creating the zip file to a network drive with aforementioned function. Now I've noticed that the same (similar) thing occurs also, when the target drive is a USB stick, that is almost full, so that during the execution of the function the drive becomes full.
In January, I was using VS 2019 with .Net Framework 4.7.1, now I've switched to .Net 4.8. As far as I can tell, my Visual studio is up-to-date with updates.
Original Comments
Feedback Bot on 8/30/2022, 01:03 AM:
(private comment, text removed)
Dan Moseley [MSFT] on 11/8/2022, 09:10 PM:
(private comment, text removed)
Original Solutions
(no solutions)
Author:
vsfeedback
Assignees:
Labels:
area-System.IO.Compression
,
untriaged
Milestone:
Did another example project of this, and added dump file as well as screenshot of stack trace from garbage collector thread causing the problem
Dump file:
https://drive.google.com/file/d/1uFmGA6Acq6keNc7aRd1mf1hBcSDTni78/view?usp=sharing
ZipTester.sln.zip
There is not enough space on the disk.
It looks like you don't have enough disk space to create zip file from given folder.
In January, the crash occurred when creating the zip file to a network drive with aforementioned function. Now I've noticed that the same (similar) thing occurs also, when the target drive is a USB stick, that is almost full, so that during the execution of the function the drive becomes full.
Was the network drive almost full as well?
needs-author-action
An issue or pull request that requires more info or actions from the author.
and removed
untriaged
New issue has not been triaged by the area owner
labels
Jan 11, 2023
runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs
Lines 128 to 132
d87f7b2
But it may on .NET Framework:
https://referencesource.microsoft.com/#mscorlib/system/io/filestream.cs,1288
Since it's not a security issue, we won't backport the fix to .NET Framework.
I did a quick search and it seems that there is no way to tell .NET Framework to not crash the application on unhandled finalizer thread exceptions. We can do it for:
Task exceptions:
https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/throwunobservedtaskexceptions-element
WinForms threads exceptions:
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.application.setunhandledexceptionmode?view=netframework-4.8.1
I've take a look at your code sample:
try {
ZipFile::CreateFromDirectory("C:\\temp\\temp", targetZip);
catch (...) {
return -1;
Since ZipFile::CreateFromDirectory
returns void there is nothing we can do. You could always try to re-implement this method by using ZipArchive
directly (create it from a file stream) and own the FileStream
and supress the finalization on your own, but you would need to mimic everything the method does. Some conceptual pseudocode below:
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
namespace ZipFull
internal class Program
static void Main(string[] args)
string source = args[0];
string dest = args[1];
using (FileStream fs = File.Create(dest))
GC.SuppressFinalize(fs); // supress FileStream finalization
using (ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Create))
// iterate over all files in source and add entires
DirectoryInfo sourceDirectory = new DirectoryInfo(source);
foreach (FileSystemInfo file in sourceDirectory.EnumerateFileSystemInfos("*", SearchOption.AllDirectories))
if (file is FileInfo)
archive.CreateEntryFromFile(file.FullName, file.Name);
else if (file is DirectoryInfo di && !di.EnumerateFileSystemInfos().Any())
archive.CreateEntry("$getTheName");
needs-author-action
An issue or pull request that requires more info or actions from the author.
label
Jan 12, 2023