Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix preserved reference surrogate in collection deserialization bug #264

Conversation

Arkatufus
Copy link
Contributor

Closes #263

@Arkatufus
Copy link
Contributor Author

Problem was caused by wrongly stored reference in DeserializeSession: #263 (comment)

@@ -65,6 +65,15 @@ public object GetDeserializedObject(int id)
return _objectById[id];
}

public void ReplaceOrAddTrackedDeserializedObject([NotNull] object origin, [NotNull] object replacement)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method will search the current reference array for surrogated object instance and replace it with the actual object reference value

@@ -37,6 +42,8 @@ public override object ReadValue(Stream stream, DeserializerSession session)
{
var surrogateValue = _surrogateSerializer.ReadValue(stream, session);
var value = _translator(surrogateValue);
if(_preserveObjectReferences)
session.ReplaceOrAddTrackedDeserializedObject(surrogateValue, value);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the wrongly injected surrogate object with the actual deserialized de-surrogated value.
Value might be wrongly stored by _surrogateSerializer.ReadValue() in line 43.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boy this must have been a fun one to track down.

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - can't see this having any wire format impact since it's all read-side.

@@ -37,6 +42,8 @@ public override object ReadValue(Stream stream, DeserializerSession session)
{
var surrogateValue = _surrogateSerializer.ReadValue(stream, session);
var value = _translator(surrogateValue);
if(_preserveObjectReferences)
session.ReplaceOrAddTrackedDeserializedObject(surrogateValue, value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boy this must have been a fun one to track down.

@Aaronontheweb Aaronontheweb merged commit 41ceaaa into akkadotnet:dev Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deserializing a message with two ActorPaths to the same actor throws an invalid cast exception
2 participants