This project is read-only.

Unable to serialize model with Highcharts property

Jan 31, 2014 at 3:54 PM
Firstly apology for my English, as I'm not the best at explaining things, but here goes

Using MVC I have the following model
    public class MyClass
          public Dictionary<string, Highcharts> MyProperty{ get; set; } 
When I come to serialize the model using
var serializer = new DataContractSerializer(typeof(MyClass));
                    string xmlString;

                    using (var sw = new StringWriter())
                        using (var writer = new XmlTextWriter(sw))
                            writer.Formatting = Formatting.Indented;
                            serializer.WriteObject(writer, model);
                            xmlString = sw.ToString();
I'm getting the following error:
Additional information: Type 'DotNet.Highcharts.Highcharts' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.

I'm not sure how to get around this problem, as don't have access to high charts class to make any changes, searching the web it also seems the problem could be that Highcharts class does not have a constructor that takes zero parameters but again i can't add this in myself.

Any help on getting around this issue would be great thanks.l
Feb 13, 2014 at 8:27 PM
Hi, I had a similar question. Is there a way to Serialize a highchart in a controller and return the JSON string? When I attempt to serialize the object it returns a empty string.

Here's an example of what I'm talking about.
    public string RequestChart()

        DotNet.Highcharts.Highcharts chart = fooMethod();

        var json = JsonConvert.SerializeObject(chart );

        return json;
In this example the var json is set to "".

Thanks for any help or for pointing me in a right direction!