akkadotnet / akkadotnet/Hyperion

Preserving object references doesn't work

Open
#85 0 comments 1 reaction 1 assignee View on GitHub

@Horusiath is already working on this.

Since Jan 8, 2018.

bug
Dominant language
C#
Stars
281
Forks
62
PR merge metrics
No merged PRs in 30d

Description

While working on #82 I've found out that SerializerOptions.PreserveObjectReferences actually never worked for user-defined objects. Example:

var serializer = new Serializer(new SerializerOptions(preserveObjectReferences: true));
var serializerSession = new SerializerSession(serializer);
var deserializerSession = new DeserializerSession(serializer);

using (var stream = new MemoryStream())
{
    var o = new MyClass {First = "hello", Second = 123};

    serializer.Serialize(o, stream, serializerSession); // serialize object 1st time
    stream.Position = 0;
    serializer.Serialize(o, stream, serializerSession); // serialize it again using the same session
}

First serialization passes, but second one throws ArgumentException: An item with the same key has already been added.. From what I've seen, generated object serializer simply doesn't look it object has been saved previously before trying to serialize it again.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.