locked
Error Circular Reference RRS feed

  • Question

  • Hi people.

    I need convert my object Microsoft.AnalysisServices.AdomdClient.CubeDef to json file...

    this is my code:

    Microsoft.AnalysisServices.AdomdClient.CubeDef xs = c;

    var jso = new JavaScriptSerializer().Serialize(c);

    When i try do that, show error menssage.

    Somenone know any workaround for i do this???

    Tks!

    Wednesday, August 10, 2016 8:11 PM

Answers

  • I cannot really answer how to get the data out of your cube because it is partially dependent upon how your dimensions are set up. You'll just have to look at the data you're getting and find what you need.

    For the actual payload in JSON a simple type containing properties for each of the root elements is sufficient. The arrays in JSON can be lists or arrays in the object. Something like this would serialize down to equivalent JSON (but you'll need to tweak it).

    class Data
    {
       //Could also use IEnumerable or arrays if needed
       public List<string> Rows { get; set; }
       public List<string> Cols { get; set; }
       public List<string> Vals { get; set; }
       
       public string AggregatorName { get; set; }
       public string RendererName { get; set; }
    }

    You may also need to adjust the JSON formatter to get the JSON rendered the way you want (casing, null handling, etc).

    Michael Taylor
    http://www.michaeltaylorp3.net

    • Proposed as answer by Hart Wang Tuesday, August 16, 2016 2:57 AM
    • Marked as answer by DotNet Wang Friday, August 19, 2016 1:19 AM
    Thursday, August 11, 2016 11:27 PM

All replies

  • Please post a concise and complete example as console application.
    Wednesday, August 10, 2016 8:52 PM
  • this is web application, ef, mvc 5, analysis services...
    Wednesday, August 10, 2016 8:56 PM
  • hmm, OOP. It should be no problem to decoupe the analysis part.

    Without code it's pretty hard to determine the reason.

    Wednesday, August 10, 2016 9:18 PM
  • here is all my code

     

      protected Microsoft.AnalysisServices.AdomdClient.CubeCollection cf;
           

        public ActionResult Index()
            {
                AdomdConnection con = new                                      AdomdConnection("Provider=MSOLAP;DataSource=192.168.50.200\\SQLBI;Catalog=PAGAR;");

               con.Open();
                cf = con.Cubes;

     foreach (CubeDef c in con.Cubes)
                {
                    switch (c.Name)
                    {
                        case "DW_PAGAR":
                            var obi = c.Dimensions;

                            CubeDef xs = c;
                         
                                var json = new JavaScriptSerializer().Serialize(c);

                      }

                 }

    Message error:

    A Circular reference was detected while serializing

    • Edited by fGolden Thursday, August 11, 2016 1:30 PM
    Thursday, August 11, 2016 1:21 PM
  • hmm, you should have posted the correct error message in the first place..

    There are certain object graph relations which cannot be handled by the default serializer. So need a custom serializer to create your JavaScript.

    Thursday, August 11, 2016 2:11 PM
  • Right, i understand this error, but i don't know how custom serializer

    Can you help me?? i'm trying to solve this about 2~3 days

    How i do custom serializer??

    Thanks

    • Edited by fGolden Thursday, August 11, 2016 2:22 PM
    Thursday, August 11, 2016 2:20 PM
  • Try JSON.NET. It can imho handle circular references. You can install it via nuget.
    Thursday, August 11, 2016 2:57 PM
  • You cannot convert CubeDef straight to JSON as it is too complex (circular references, etc). Instead you need to identify the pieces of the object you actually need and then serialize just that to JSON. In my opinion the best way to do that is to create a custom type that takes a CubeDef as a parameter and sets the properties on the type that you need serialized. Then serialize the custom type.

    Michael Taylor
    http://www.michaeltaylorp3.net

    Thursday, August 11, 2016 3:02 PM
  • Got it, i was thinking that too but, i did not find exactly the pieces i need for set properties in my custom type.

    When i use watch in CubeDef have so many collections inside him, just find it dimensions and attribute that i need and don't find values from this attribute, how can i set values from this attribute into custom type?? 


    To understand better what i want to do is something like that:

    https://jsfiddle.net/w86bgq9o/256/

    Turn CubeDef or CustomType into json and throw then to pivotTable.

    Thursday, August 11, 2016 5:52 PM
  • I cannot really answer how to get the data out of your cube because it is partially dependent upon how your dimensions are set up. You'll just have to look at the data you're getting and find what you need.

    For the actual payload in JSON a simple type containing properties for each of the root elements is sufficient. The arrays in JSON can be lists or arrays in the object. Something like this would serialize down to equivalent JSON (but you'll need to tweak it).

    class Data
    {
       //Could also use IEnumerable or arrays if needed
       public List<string> Rows { get; set; }
       public List<string> Cols { get; set; }
       public List<string> Vals { get; set; }
       
       public string AggregatorName { get; set; }
       public string RendererName { get; set; }
    }

    You may also need to adjust the JSON formatter to get the JSON rendered the way you want (casing, null handling, etc).

    Michael Taylor
    http://www.michaeltaylorp3.net

    • Proposed as answer by Hart Wang Tuesday, August 16, 2016 2:57 AM
    • Marked as answer by DotNet Wang Friday, August 19, 2016 1:19 AM
    Thursday, August 11, 2016 11:27 PM
  • this is web application, ef, mvc 5, analysis services...

    Hi fGolden,

    Thank you for posting here.

    Since your issue is related to ASP.NET. I would suggest you post on ASP.NET forum.

    The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries,

    samples, and tools.

    Please remember to close your thread by marking useful posts as answer.

    Best Regards,

    Hart


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Tuesday, August 16, 2016 2:54 AM