Skip to content

.Net 6/7 IAsyncDisposable uses wrong DisposeAsync method #730

@roddone

Description

@roddone

Steps to reproduce

  1. Create a project targeting .net 6 or higher
  2. use ZipOutputStream with "await using"
  3. Or call directly .DisposeAsync() on previously created ZipOutputStream

Expected behavior

When Disposing, or calling .DisposeAsync(), it uses DeflaterOutputStream.DisposeAsync()

Actual behavior

When Disposing, it uses the base class Stream.DisposeAsync() instead of DeflaterOutputStream.DisposeAsync() method.
This is caused by a compilation directive #if NETSTANDARD2_1 that does not take in consideration recent .net versions (.Net 6 and 7, and probably 5, I have not tested this version)
image

Version of SharpZipLib

  • Compiled from source (latest commit on master)

full sample to reproduce (must create a .net 6 project) :

using ICSharpCode.SharpZipLib.Zip;
using System.Text;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", async (HttpContext context) =>
{
	await using (var outputStream = new MemoryStream())
	{
		await using (var stream = new ZipOutputStream(outputStream))
		{
			//add file without compression
			await stream.PutNextEntryAsync(new ZipEntry("test.txt") { CompressionMethod = CompressionMethod.Stored });

			var bytes = Encoding.UTF8.GetBytes("ah ah !");
			await stream.WriteAsync(bytes);

			await stream.FinishAsync(CancellationToken.None);
			outputStream.Position = 0;
			await outputStream.CopyToAsync(context.Response.Body);
		}
	}
});

app.Run();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions