Curse you copy/paste gremlin!

I was on to deserializing my Windows Phone 7 game data when I ran across this oh-so helpful exception:

System.InvalidOperationException was unhandled Message=There is an error in XML document (0, 0).

And the cause?  I copy and pasted the code for both the turn class and the tiles list .  However, I didn’t update the stream name (turnStream).

IsolatedStorageFileisolatedStorageFile=IsolatedStorageFile.GetUserStoreForApplication();
//Turn
IsolatedStorageFileStreamturnStream=isolatedStorageFile.OpenFile("turn",FileMode.Open);
XmlSerializerturnSerializer=newXmlSerializer(typeof(List<Turn>));
Game.Turns=(List<Turn>)turnSerializer.Deserialize(turnStream);
 
//Tile
IsolatedStorageFileStreamtileStream=isolatedStorageFile.OpenFile("tiles",FileMode.Open);
XmlSerializertileSerializer=newXmlSerializer(typeof(List<Tile>));
Game.BoardFactory.Tiles=(List<Tile>)turnSerializer.Deserialize(turnStream);

This is another good example of why you should break out 1 task into its own function – I would have gotten a compile exception right away and wouldn’t have spent a hour chasing down ghosts in my object model and other such red herrings…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: