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
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)
Version of SharpZipLib
Compiled from source (latest commit on master)
full sample to reproduce (must create a .net 6 project) :
usingICSharpCode.SharpZipLib.Zip;usingSystem.Text;varbuilder=WebApplication.CreateBuilder(args);varapp=builder.Build();app.MapGet("/",async(HttpContextcontext)=>{awaitusing(varoutputStream=newMemoryStream()){awaitusing(varstream=newZipOutputStream(outputStream)){//add file without compressionawaitstream.PutNextEntryAsync(newZipEntry("test.txt"){CompressionMethod=CompressionMethod.Stored});varbytes=Encoding.UTF8.GetBytes("ah ah !");awaitstream.WriteAsync(bytes);awaitstream.FinishAsync(CancellationToken.None);outputStream.Position=0;awaitoutputStream.CopyToAsync(context.Response.Body);}}});app.Run();
Good catch, it should be NETSTANDARD2_1_OR_GREATER instead. It shouldn't happen unless you change the TargetFrameworks in the .csproj though? Right now we are only targeting netstandard2.0, netstandard2.1 and net45, so it shouldn't be a problem.
It also happens when you generate the nuget package from source and reference it in a .net 6 project. That's how I spotted the issue.
To find what caused it, I've added the .net6.0 in targetframeworks (for testing only) ;)
When running the example you provided above, I don't get any errors and it seems to work fine.
The compiler directives are interpreted when you are building the library, and since the targets does not include net6.0 you should get the library targeting netstandard2.1 when using it with a NET 6.0 project.
Activity
piksel commentedon Feb 23, 2022
Good catch, it should be
NETSTANDARD2_1_OR_GREATERinstead. It shouldn't happen unless you change theTargetFrameworksin the .csproj though? Right now we are only targetingnetstandard2.0,netstandard2.1andnet45, so it shouldn't be a problem.roddone commentedon Feb 23, 2022
It also happens when you generate the nuget package from source and reference it in a .net 6 project. That's how I spotted the issue.
To find what caused it, I've added the .net6.0 in targetframeworks (for testing only) ;)
piksel commentedon May 24, 2022
When running the example you provided above, I don't get any errors and it seems to work fine.
The compiler directives are interpreted when you are building the library, and since the targets does not include
net6.0you should get the library targetingnetstandard2.1when using it with a NET 6.0 project.piksel commentedon May 24, 2022
In any case, this is fixed in #755 that actually adds support for .NET 6.0 target.