How to serialize and save for Win8?

Because .Net 4.5 blacklisted a bunch of old assemblies, all the ways I know for serializinf/deserializing and saveing/loading files don’t work when building from Unity to Win8. I’ve been trying to figure out something new, but progress is slow because Mono runs on an earlier version of .NET so it allows things that I can’t actually use. I would really appreciate some advice on fairly simple ways to serialize classes and save them out when making games for Win8.

Here’s a few methods that serialize and deserialize to and from XML using XmlSerializer, According to [msdn][1] it is supported in .Net 4.5, this will allow you to input the object you want to serialize and then serialize it into Xml and then input a XMLNode.OuterXML and a XMLSerializer (containing the node type) deserialize it.

 public XmlDocument SerializeObject(object pObject)
 {
     XmlSerializer xmlSer = new XmlSerializer(pObject.GetType());
     TextWriter textWriter = new StringWriter();
     xmlSer.Serialize(textWriter, pObject);
    
     XmlDocument xdoc = new XmlDocument();
     xdoc.LoadXml(textWriter.ToString());
     return xdoc;
 }
    
 public object DeserializeObject(string pXmlizedString, XmlSerializer xs)
 {
     MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
     return xs.Deserialize(memoryStream);
 }

 byte[] StringToUTF8ByteArray(string pXmlString)
 {
     UTF8Encoding encoding = new UTF8Encoding();
     byte[] byteArray = encoding.GetBytes(pXmlString);
     return byteArray;
 }

Hope this helped :slight_smile:
[1]: XmlSerializer Class (System.Xml.Serialization) | Microsoft Learn

Here’s also something that might help you with JSON serialization. :slight_smile: How to: use DataContractJsonSerializer - WCF | Microsoft Learn

There is a good Serializer I got from http://whydoit.com/.
Very easy to use and well documented.