- Home /
New to XML in C#, can't get anything to work.
Currently the error I keep running into is :
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).
So what I'm trying to achieve is, I have a main list of SoundElement and every SoundElement has a ByteInfo object within them. I want to go through the list of SoundElement's and save out the ByteInfo Data of each one..
I have removed stuff that shouldn't be relevant form the code to make this post shorter.
SoundElement
using System.Xml;
using System.Xml.Serialization;
public class SoundElement : MonoBehaviour
{
[XmlAttribute]
public ByteInfo _byteInfo;
}
ByteInfo
[XmlType("ByteInfo")]
public class ByteInfo : MonoBehaviour
{
//trackInfo
[XmlElement("byteLength")]
public float byteLength;
[XmlElement("byteDirectory")]
public string byteDirectory;
[XmlElement("byteName")]
public string byteName;
[XmlElement("byteFav")]
public bool byteFav;
}
SoundList
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using System.Xml;
using System.Xml.Serialization;
using System.Linq;
using System.IO;
[XmlRoot("ByteList")]
public class SoundListNew : MonoBehaviour
{
[XmlArray("Bytes")]
[XmlArrayItem("Byte")]
public List<ByteInfo> clipArray;
}
This has left me with a headache and sorting this out as soon as possible would be really really nice. Any help appreciated.
Answer by Cocobongo · Jan 12, 2015 at 01:32 PM
The exception is telling you that UnityEngine.Transform
cannot be XML-serialized. From your code, it seems like the problem would come from ByteInfo
and SoundListNew
(since they inherit from MonoBehaviour
and therefore have a Transform
object).
If those do not have to be behaviours, try not making them inherit MonoBehaviour
.
While not specifically the answer I was looking for, it led me to the right path in the end :) Thanks
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Runtime instantiation based on XML 1 Answer
how can i deserialize xml to vector4 List?? 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers