I'm making an app where the order and properties of the views on a page can be changed. I'm trying to serialize the StackLayout that contains the views.
I've tried 3 different serialization techniques, all of which have failed with the following exceptions:
XmlSerializer:
System.InvalidOperationException: There was an error reflecting type 'AppProject.MyApp'. occurred
Newtonsoft.Json:
Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'ParentView' with type 'Xamarin.Forms.StackLayout'. Path 'Pages[0].stack.Children[0]'.
BinaryFormatter:
System.Runtime.Serialization.SerializationException: Type 'AppProject.MyApp' in Assembly 'AppProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
Can someone please recommend a solution?
Thanks.
Answers
I was actually able to serialize the views by using:
However, when deserializing with
myApp = JsonConvert.DeserializeObject<MyApp>(newjson, settings);
I get the this error:Does anyone know a way around this?
Thanks.
bump
Rather than literally serializing the view, I would define a model object(s) that describe the layout and then you create a view according to that model.
I'm freehanding this so excuse any syntax issues, but basically take this JSON:
And do this: