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

Preserving object references doesn't work #85

Open
Horusiath opened this issue Jan 8, 2018 · 0 comments
Open

Preserving object references doesn't work #85

Horusiath opened this issue Jan 8, 2018 · 0 comments
Assignees
Labels

Comments

@Horusiath
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant