I have a combined XNA-Silverlight project that I am developing, and I am trying to add XML content to it. Before this, I had the following setup:
- Content Project
- XNA Game Library - references the content project
- Silverlight Project - references the XNA game library
I had images in the content project, and I could compile and load them just fine from the Silverlight code. Now I am trying to add XML content to the content project and code to the game library that describes it, but I must be doing something wrong because I get the following error: There was an error while deserializing intermediate XML. Cannot find type "CrystalLib.Map"
In the content project I have a folder called maps, and under it I have the following xml file:
<?xml version="1.0" encoding="utf-8"?>
<XnaContent>
<Asset Type="CrystalLib.Map">
<TileSetFile>grassland</TileSetFile>
<Dimensions>500 250</Dimensions>
<Tiles>
... Lots of integers (500 x 250)
</Tiles>
</Asset>
</XnaContent>
Then I have the following class in the xna game project (Map.cs):
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
namespace CrystalLib
{
/// Represents the data stored in a map file
class Map
{
/// The name of tile set file
private string tileSetFile;
/// The name of tile set file
public string TileSetFile
{
get { return tileSetFile; }
set { tileSetFile = value; }
}
/// The dimensions of the map, in tiles.
private Point dimensions;
/// The dimensions of the map, in tiles.
public Point Dimensions
{
get { return dimensions; }
set { dimensions = value; }
}
/// Spatial array for the tiles for this map.
private int[] tiles;
/// Spatial array for the tiles for this map.
public int[] Tiles
{
get { return tiles; }
set { tiles = value; }
}
/// Retrieves the base layer value for the given map position.
public int GetTile(int x, int y)
{
return tiles[y * dimensions.X + x];
}
/// Read a Map object from the content pipeline.
public class MapReader : ContentTypeReader<Map>
{
protected override Map Read(ContentReader input, Map existingInstance)
{
Map map = existingInstance;
if (map == null)
{
map = new Map();
}
map.TileSetFile = input.ReadString();
map.Dimensions = input.ReadObject<Point>();
map.Tiles = input.ReadObject<int[]>();
return map;
}
}
}
}
What else do I need?