Repository navigation
fix(serialization): record deserialized Stack<T> for reference tracking - #11612
Open
johnkaram02 wants to merge 1 commit into
Open
johnkaram02 wants to merge 1 commit into
johnkaram02 wants to merge 1 commit into
Conversation
StackCodec<T>.ReadValue recorded the temporary element array in the
reference table instead of the Stack<T> it returns. When an object graph
contains the same Stack<T> instance more than once, the serializer writes
later occurrences as references, and reading one of them resolved to the
array and threw InvalidCastException ("Unable to cast object of type
'System.Int32[]' to type 'System.Collections.Generic.Stack`1[System.Int32]'").
The codec now records the Stack<T> instance, so shared references
deserialize to the same stack.
This branch has not been deployed
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
StackCodec<T>.ReadValuerecords the temporary element array in the session's reference table instead of theStack<T>it returns. If an object graph contains the sameStack<T>instance more than once, the writer emits later occurrences as references. Reading one of those references resolves to the array, and deserialization fails:Solution
Record the
Stack<T>instance (result) instead of the array, which matches the other collection codecs such asQueueCodec. The wire format does not change.StackCodecTests.PreservesSharedStackReferencesround-trips a list that holds the same stack twice. It checks that both entries deserialize to the sameStack<T>instance with the original contents.Microsoft Reviewers: Open in CodeFlow