ZipReader OpenEntryStream / WriteEntryTo NullReferenceException with .NET 6.0 #481

Closed
opened 2026-01-29 22:12:46 +00:00 by claunia · 1 comment
Owner

Originally created by @Pyroluk on GitHub (Nov 17, 2021).

Hi,

ZipReader's OpenEntryStream() and WriteEntryTo() are throwing NullReferenceException when using .NET 6. Same code works perfectly fine with .NET 5.

string expectedTestResult = "";

using (var inputMs = new MemoryStream(Encoding.UTF8.GetBytes(xmlFileElement.Attribute("testResults").Value)))
using (CryptoStream base64Stream = new CryptoStream(inputMs, new FromBase64Transform(), CryptoStreamMode.Read))
using (var zipReader = ReaderFactory.Open(base64Stream))
using (var outputMs = new MemoryStream())
{
    zipReader.MoveToNextEntry();
    using (var zipStream = zipReader.OpenEntryStream())
        zipStream.CopyTo(outputMs);
    expectedTestResult = Encoding.UTF8.GetString(outputMs.ToArray());
}

Hope it is a quick and easy fix.

Thank you for providing this awesome project.

Cheers!

Originally created by @Pyroluk on GitHub (Nov 17, 2021). Hi, ZipReader's OpenEntryStream() and WriteEntryTo() are throwing NullReferenceException when using .NET 6. Same code works perfectly fine with .NET 5. ``` string expectedTestResult = ""; using (var inputMs = new MemoryStream(Encoding.UTF8.GetBytes(xmlFileElement.Attribute("testResults").Value))) using (CryptoStream base64Stream = new CryptoStream(inputMs, new FromBase64Transform(), CryptoStreamMode.Read)) using (var zipReader = ReaderFactory.Open(base64Stream)) using (var outputMs = new MemoryStream()) { zipReader.MoveToNextEntry(); using (var zipStream = zipReader.OpenEntryStream()) zipStream.CopyTo(outputMs); expectedTestResult = Encoding.UTF8.GetString(outputMs.ToArray()); } ``` Hope it is a quick and easy fix. Thank you for providing this awesome project. Cheers!
Author
Owner

@Pyroluk commented on GitHub (Nov 19, 2021):

For some reason the chain for creating the base64 string omitted a blank at the end of the string in .net 6.
That messed up everything.

@Pyroluk commented on GitHub (Nov 19, 2021): For some reason the chain for creating the base64 string omitted a blank at the end of the string in .net 6. That messed up everything.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#481