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 3428760
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:59:52+00:00 2026-05-18T06:59:52+00:00

I have a graph object, that I need to serialize. Nomatter which members i

  • 0

I have a graph object, that I need to serialize. Nomatter which members i implement, the method returns {}

string json = new JavascriptSerializer().Serialize(routeGraph);

Here is my graph class:

namespace GraphClass
{
    [Serializable, DataContract]
    public class Graph : ISerializable
    {
        [DataMember]
        readonly Dictionary<string, Node> nodeMap = new Dictionary<string, Node>();
        [DataMember]
        private Tuple<string, string, double> bufferOriginalOffer;
    }
    [Serializable, DataContract]
    public class Node : ISerializable
    {
        [DataMember]
        public string Name { get; private set; }
        [DataMember]
        public List<Edge> Adj { get; private set; }
        [DataMember]
        public Node Prev { get; set; }
        [DataMember]
        public double Distance { get; set; }
    [Serializable, DataContract]
    public class Edge : IComparable, ISerializable
    {
        [DataMember]
        public Node Destination { get; private set; }
        [DataMember]
        public double Cost { get; set; }
        [DataMember]
        public double Time { get; set; }
    }
    [Serializable, DataContract]
    public class Tuple<T, T1, T2> : ISerializable
    {
        [DataMember]
        public T Item1 { get; set; }
        [DataMember]
        public T1 Item2 { get; set; }
        [DataMember]
        public T2 Item3 { get; set; }
    }
}

I’ve tried for a whole day, to serialize this to either JSON or XML, as I have to send the object to a webservice.

UPDATE:
Used DataContractJsonSerialiser instead. I get the following error:

Object graph for type 'GraphClass.Edge' contains cycles and cannot be serialized if reference tracking is disabled.

As you can see in the Node class, a Node can contain a list of edges. I’m at a loss about fixing the error though.

  • 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-18T06:59:53+00:00Added an answer on May 18, 2026 at 6:59 am

    Did you perhaps intend to use DataContractJsonSerializer ? This is more data-contract oriented; JavascriptSerializer doesn’t really care at all about data-contracts – it just looks at the type meta.

    Graph only has private fields; JavascriptSerializer only looks at public members. Add a public property for nodeMap, perhaps?

    Note that [Serializable] does nothing here, and those types don’t implement ISerializable etc, despite claiming to.


    Edit: confirmed the following seems to work OK:

    DataContractJsonSerializer ser = new DataContractJsonSerializer(graph.GetType());
    string s;
    using(var ms = new MemoryStream()) {
        ser.WriteObject(ms, graph);
        s = Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length);
    }
    Console.WriteLine(s);
    

    and the following seems to work after adding a property:

    public Dictionary<string, Node> NodeMap { get { return nodeMap; } }
    ...
    JavaScriptSerializer ser = new JavaScriptSerializer();
    string s = ser.Serialize(graph);
    Console.WriteLine(s);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object graph that I need to serialize to xml and save
I have a pretty sizeable object graph that I have serialized to a file
The situation is this: You have a Hibernate context with an object graph that
I have an object graph serialized to xaml. A rough sample of what it
I have this object graph, I want to map: abstract Account (username, password, ...)
So I have an object graph, let's just say it's an order. You have
I have a Samurize config that shows a CPU usage graph similar to Task
I have a web page that displays a long line graph inside a div
I have a Graph being drawn inside a UIScrollView . It's one large UIView
I have a DirectShow graph to render MPEG2/4 movies from a network stream. When

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.