Repository navigation
Fix NeoBinary serialization of DataSets and DataTables larger than 4 KB - #251
Merged
theRainbird merged 1 commit intoNov 17, 2026
Conversation
SerializeDataSet and SerializeDataTable wrote the XML schema and the DiffGram into a MemoryStream that wrapped a fixed 4096 byte buffer rented from the ArrayPool. Such a stream cannot grow, so any DataSet or DataTable whose XML exceeded 4 KB failed with "NotSupportedException: Memory stream is not expandable". Write the XML into StringWriter instances instead. They grow as needed, match the StringReader used on the deserialization side and avoid the UTF-8 round trip. The wire format stays a length-prefixed string. Add regression tests with 2000 rows (relation, DBNull, modified row, multi-byte characters) for DataSet and DataTable. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
theRainbird
self-requested a review
November 17, 2026 21:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
NeoBinarySerializer.SerializeDataSetandSerializeDataTable(XML mode, the default) write the XML schema and the DiffGram into aMemoryStreamthat wraps a fixed 4096 byte buffer rented from theArrayPool. Such a stream cannot grow. EveryDataSetorDataTablewhose XML is larger than 4 KB (roughly 10 to 30 rows) therefore fails:Fix
The schema and the DiffGram are written into
StringWriterinstances instead. They grow as needed, match theStringReaderthat the deserialization side already uses, and the XML no longer takes a detour through UTF-8 bytes. The serialization is moved into one helper,WriteXmlSchemaAndDiffGram, that is shared by the DataSet and the DataTable path. The deserialization code is not changed. The data is still written as two length-prefixed strings.Tests
Two regression tests with 2000 rows (DataSet with a relation, a primary key, a
DBNulldefault value, a modified row and multi-byte characters; DataTable with a modified row). Both fail onmasterwith the exception above and pass with this change. The serialization, DataSet and NeoBinary tests pass on net8.0.