So i have a class, Texture2DProcessor, that inherits IXmlSerializable and Implicitly casts to and from Texture2D
public static implicit operator Texture2D(Texture2DProcessor o)
{
return o.Data;
}
public static implicit operator Texture2DProcessor(Texture2D o)
{
return o == null ? null : new Texture2DProcessor(o);
}
I then have a struct, GunProperties, that contains a Texture2D property with an XmlElement attribute with the type set to Texture2DProcessor
Texture2D _sideSprite;
[XmlElement(typeof(Texture2DProcessor))]
public Texture2D SideSprite
{
get { return _sideSprite; }
set { _sideSprite = value; }
}
I get the following runtime error
Cannot serialize member '...GunProperties.SideSprite' of type 'Microsoft.Xna.Framework.Graphics.Texture2D'
why is XmlSerializer not using Texture2DProcessor to read and write the Xml data?
Also I know that my ReadXml and WriteXml methods work because this works fine and i am able to use the texture.
Texture2D texture;
XmlSerializer serializer = new XmlSerializer(typeof(Texture2DProcessor));
serializer.Deserialize(new FileStream(path, FileMode.Open), texture);
The reason I'm going through this trouble is I'm using monogame and the content pipeline is pretty messed up especially for custom types and other than this issue i have it all working.