I am trying to serialize data in my XNA project. I have a Texture2D background property that I use during runtime, but I also have a 'string property' to hold my Background name. This will allow me to serialize the asset name so I can later use the info to de-serialize later and load into my game.

Problem is myTexture.Name property is suppose to hold the Asset Name but when I try to serialize into an XML file, the BackgroundName Element is empty.

Here is what the Property code looks like:

//This property is Only used for serialization, 
//myTexture is Texture2D and is assigned in the ctor of the class
public string BGName { get { return this.myTexture.Name;} set{/*Empty on purpose*/} }

//used at runtime of game
public Texture2D BG { get { return this.myTexture;} set{ this.myTexture = value; } }

Could someone please advise, how to retrieve the asset name from a Texture2D, according to MSDN, this field holds the name of the texture.

I found the answer in another forum. The Texture2D.Name property is open for the developer to get/set. It is not used by XNA's GraphicsDevice.

This question has already been answered. Start a new discussion instead.