Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5948789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:09:30+00:00 2026-05-22T17:09:30+00:00

while playing with the newly released protobuf.net, we are encountering the issue illustrated in

  • 0

while playing with the newly released protobuf.net, we are encountering the issue illustrated in the code below:

[ProtoContract]
class Node
{
    public Node()
    {
        ChildLinks = new List<Link>();
        ParentLinks = new List<Link>();
    }

    [ProtoMember(1, IsRequired = true)]
    public string Data { get; set; }

    [ProtoMember(2, IsRequired = true)]
    public List<Link> ChildLinks { get; set; }

    [ProtoMember(3, IsRequired = true)]
    public List<Link> ParentLinks { get; set; }

    public void AddChild(Node child)
    {
        Link link = new Link { Parent = this, Child = child };
        ChildLinks.Add(link);
        child.ParentLinks.Add(link);
    }
}

[ProtoContract]
class Link
{
    [ProtoMember(2, AsReference = true, IsRequired = true)]
    public Node Child { get; set; }

    [ProtoMember(3, AsReference = true, IsRequired = true)]
    public Node Parent { get; set; }
}

public static void Main()
{
    Node node = new Node { Data = "parent" };
    node.AddChild(new Node { Data = "child" });

    using (MemoryStream memStream = new MemoryStream())
    {
        Serializer.Serialize(memStream, node);
        memStream.Position = 0;
        Node deserialized = Serializer.Deserialize<Node>(memStream);

        Link childLink = deserialized.ChildLinks.Single();
        Debug.Assert(ReferenceEquals(childLink, childLink.Child.ParentLinks.Single()));
    }
}

The assert throws an exception… Our goal here is to have a unique instance of a Link object in the ChildLinks and ParentLinks properties. We tried the AsReference attribute but it didn’t work…

Does anyone know how we could fix that ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:09:30+00:00Added an answer on May 22, 2026 at 5:09 pm

    I still need to assess the impact (not something to dry doing while my head feels like cheese), but there is a …. trouble-spot with the root object in the graph – meaning: because I usually handle the reference tracking while walking the association, and on the root object there is no association. I guess I can probably address this with some type-level attribute instead (i.e. always treat as a reference).

    Anyway, for now you can side-step this by adding one more level to the graph (artificially adding an association), i.e.

    static class Program
    {
        public static void Main()
        {
    
            Node node = new Node { Data = "parent" };
            node.AddChild(new Node { Data = "child" });
            using (MemoryStream memStream = new MemoryStream())
            {
                Serializer.Serialize(memStream, new NodeWrapper { Root = node });
                memStream.Position = 0;
                Node deserialized = Serializer.Deserialize<NodeWrapper>(memStream).Root;
    
                Link childLink = deserialized.ChildLinks.Single();
                Debug.Assert(ReferenceEquals(childLink, childLink.Child.ParentLinks.Single()));
            }
        }
    }
    [ProtoContract]
    class NodeWrapper
    {
        [ProtoMember(1, AsReference = true, IsRequired = true)]
        public Node Root {get;set;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today while playing with a De-compiler, i Decompiled the .NET C# Char Class and
I am having a crash issue while playing video in iphone 4.0 OS. Actually,
Issue summary Changing the orientation of an iPad device or simulator while playing a
I was working on a project and, while playing around with the code, I
While playing with VS11 beta I noticed something weird: this code couts f took
I am getting below error while playing audio. Is this the reason for not
I'm new to Reactive Extensions for .NET and while playing with it I thought
I stumbled upon this oddity today while playing with some code to go down
I came across on a strange behavior of the following code, while playing around
I am revolving around with a small issue in iPhone while playing around Array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.