I get the following message when trying to use the intermediate serializer to serialize my tileset class.
Cyclic reference found while serializing Microsoft.Xna.Framework.Graphics.GraphicsDevice. You may be missing a ContentSerializerAttribute.SharedResource flag.
I don't have any references to the GraphicsDevice inside my tileset class. Here is the code
| public sealed class Tileset |
| { |
| public string AssetName { get; set; } |
| |
| [ContentSerializer(SharedResource = true)] |
| public Texture2D Texture; |
| |
| [ContentSerializer(SharedResource = true)] |
| public Rectangle[] Tile; |
| |
| public Tileset(string assetName, Texture2D texture) |
| { |
| var width = 0; |
| var height = 0; |
| var i = 0; |
| |
| AssetName = assetName; |
| |
| Texture = texture; |
| |
| width = Texture.Width / 32; |
| height = Texture.Height / 32; |
| |
| Tile = new Rectangle[width * height]; |
| |
| for (var y = 0; y < height; y++) |
| { |
| for (var x = 0; x < width; x++) |
| { |
| Tile[i] = new Rectangle(x * 32, y * 32, 32, 32); |
| i += 1; |
| } |
| } |
| } |
| } |
Just for the fun of it, I use this class that I made to do the serialization:
| public static class XmlContentCreator |
| { |
| public static void Create<T>(string filename, T value) |
| { |
| XmlWriterSettings settings = new XmlWriterSettings(); |
| settings.Indent = true; |
| |
| using (XmlWriter writer = XmlWriter.Create(filename, settings)) |
| { |
| IntermediateSerializer.Serialize(writer, value, null); |
| } |
| } |
| } |
I am not 100% sure what I am doing wrong here. I flagged what I thought to be the offending variables and still no dice. Thanks for any help in advance.