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.Dismiss alert
{{ message }}
Repository navigation
System.IO.Packaging - net8 - Package.Flush not flushing all data #114114
using System;
using System.IO;
using System.IO.Packaging;
class Program
{
public static void Main()
{
var ms = new MemoryStream();
Package package = Package.Open(ms, FileMode.OpenOrCreate);
Uri partUri = new Uri("/example.txt", UriKind.Relative);
PackagePart packagePart = package.CreatePart(partUri, "text/plain");
using (StreamWriter writer = new StreamWriter(packagePart.GetStream(FileMode.Create, FileAccess.Write)))
{
writer.Write("Hello, world!");
}
// Replacing package.Flush with package.Close() everything works fine
package.Flush();
File.WriteAllBytes("MyFile.zip", ms.GetBuffer());
}
}
Expected behavior
Save the right content without closing the package
Actual behavior
The file is truncated (or empty)
Regression?
It works with net48
Known Workarounds
No response
Configuration
Which version of .NET is the code running on? net8.0 (it works with net48
What OS and version, and what distro if applicable? Windows 11
What is the architecture (x64, x86, ARM, ARM64)? x64
Do you know whether it is specific to that configuration? It is specific with net8.0 configuration. net48 works*
Activity
dotnet-policy-service commentedon Apr 1, 2025
Tagging subscribers to this area: @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.
ericstj commentedon Apr 4, 2025
This is due to the behavior of the ZipArchive implementation on .NETCore. Zip only ever writes the archive information on close.
https://github.com/dotnet/runtime/blob/15872212c29cecc8d82da4548c3060f2614665f7/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchive.cs#L314C29-L314C38
On .NETFramework System.IO.Packaging had an entirely different implementation which would write the archive on flush:
https://referencesource.microsoft.com/#WindowsBase/Base/MS/Internal/IO/Zip/ZipArchive.cs,348
I think this is a duplicate of #24149
bubibubi commentedon Apr 4, 2025
Not so sure it's a duplicate. Flush is implemented but it's not working... It's quite different.