- Home /
Question by
Cyrax5710 · Feb 28, 2015 at 10:55 PM ·
c#serializationmonobehaviourunity 4xmlserializer
XML Serialization problem
I'm getting the following error:
InvalidOperationException: To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. UnityEngine.Transform does not implement Add(System.Object).
Here's my code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Text;
[XmlRoot("world")]
public class WorldContainer
{
[XmlArray("tile"),XmlArrayItem("item")]
public Tile[] tiles;
//load XML file
public static WorldContainer Load(string path)
{
-------> var serializer = new XmlSerializer(typeof(WorldContainer));
using(var stream = new FileStream(path, FileMode.Open))
{
return serializer.Deserialize(stream) as WorldContainer;
}
}
}
I read thorugh some other answers on here that the class to be serialized cannot inherit the MonoBehavior class, mine doesn't. Any help is greatly appreciated
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613184631im_/https://answers.unity.com/themes/thub/images/avi.jpg)