I'm having quite the problem with my XML serialization issue. I've been working on my project to (de) serialize an object that has an interface as an attribute. I know that you can't serialize an interface and that is what my error tells me.
Here is an example of the object that I want to save to a file:
public class Task
{
public int id;
public string name;
public TypeEntree typeEntree;
public int idRequired;
public string code;
public int waitTime;
public string nameApp;
// ... Constructors (empty and non-empty) and methods ...
}
TypeEntree is an empty interface, it's only to relate different objects and use them easily around my application. For instance, here are two of the objects that uses this interface:
[Serializable]
public class Mouse : TypeEntree
{
public Point point;
public IntPtr gaucheOuDroite;
public string image;
// ... Constructors (empty and non-empty) and methods ...
}
[Serializable]
public class Sequence : TypeEntree
{
public List<Tuple<string, Point, long, IntPtr>> actions;
// ... Constructors (empty and non-empty) and methods ...
}
The interface TypeEntree also has the [Serializable] attribute and also the [XmlInclude (typeof (Mouse)] for each of my classes that uses this interface.
Here is my question: Why does when I try to serialize, it cannot detects the type of my object (typeEntree in Task) since I added the [XmlInclude (typeof (Mouse)] attributes?
Also, how should I fix this issue?
Additionnally, here are the methods of serializing/deserializing I found that seems to works very well without interface: https://stackoverflow.com/a/22417240/6303528