dotnet / dotnet/Open-XML-SDK

System.IO.IOException: Stream was too long error on .NET Core 2.0 application

Open
#244 17 comments 13 reactions 0 assignees View on GitHub
blocked: corefx System.IO.Packaging bug no-issue-activity
Dominant language
C#
Stars
4.6k
Forks
605
PR merge metrics
No merged PRs in 30d

Description

In .NET Core 2 console application ([ConsoleApp1.zip](https://github.com/OfficeDev/Open-XML-SDK/files/1309342/ConsoleApp1.zip)) writing a large Excel file stops with the following error:
System.IO.IOException: Stream was too long.
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.Compression.WrappedStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.Xml.XmlUtf8RawTextWriter.FlushBuffer()
at System.Xml.XmlUtf8RawTextWriter.WriteAttributeTextBlock(Char* pSrc, Char* pSrcEnd)
at System.Xml.XmlUtf8RawTextWriter.WriteString(String text)
at System.Xml.XmlWellFormedWriter.WriteString(String text)
at DocumentFormat.OpenXml.OpenXmlElement.WriteAttributesTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlPartWriter.WriteElement(OpenXmlElement elementObject)
at ConsoleApp1.Program.WriteRandomValuesSAX(String fileName, String sheetName) in C:\Users\anton\Documents\Visual Studio 2017\Projects\ConsoleApplication2\ConsoleApp1\Program.cs:line 80
at ConsoleApp1.Program.Main(String[] args) in C:\Users\anton\Documents\Visual Studio 2017\Projects\ConsoleApplication2\ConsoleApp1\Program.cs:line 105

The application workset grew up to 4 GiB. But there is a x64 application, so the process memory is not limited by 4 GiB.

Meanwhile in .NET FW4.7 the same application ([ConsoleApp2.zip](https://github.com/OfficeDev/Open-XML-SDK/files/1309348/ConsoleApp2.zip)) works perfectly with 10 MB workset size.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.