1

Can this be done? My problem is that I have this Serializable class:

[Serializable()]
public class Car
{
    [System.Xml.Serialization.XmlElement("Make")]
    public string m_make;

    [System.Xml.Serialization.XmlElement("Owner")]
    public string m_owner;

    [System.Xml.Serialization.XmlElement("Plate")]
    public string m_plate;

    [System.Xml.Serialization.XmlElement("Type")]
    public TenantType m_type = TenantType.Test;

    public Car()
    {
    }
}

I want to add a non-serializable object (one that does not extend ISerializable) to this class, but I keep getting a runtime error: "There was an error reflecting type 'Program.Car'." I put the NonSerialized() tag before it, but I think C# still doesn't get that I won't want it to be serialized at any point.

    [NonSerialized()]
    public MyObject m_obj;
yelsayed
  • 5,236
  • 3
  • 27
  • 38
  • possible duplicate of [Difference between NonSerialized and Xml.Serialization.XmlIgnore?](http://stackoverflow.com/questions/2201658/difference-between-nonserialized-and-xml-serialization-xmlignore) – Alexei Levenkov Jan 28 '14 at 03:30

2 Answers2

4

Check out XmlIgnore might be what you are looking for.

http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlignoreattribute(v=vs.110).aspx

Tony
  • 1,297
  • 10
  • 17
1

This is a good reference. I believe you may be using the wrong Attribute.

http://msdn.microsoft.com/en-us/library/ms182349.aspx

Jason Roell
  • 6,679
  • 4
  • 21
  • 28