Need help Xna Xml Deserializing

Started by
3 comments, last by Soaps79 12 years, 2 months ago
I have been trying to figure out the cause of my problem.
Every time i try to compile it comes up with this error message.

There was an error while deserializing intermediate XML. Cannot find type "RpgLibary.ItemClasses.ContainerData". Line: 3 Column: 10

and here is my xml file

<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:ItemClasses="RpgLibary.ItemClasses">
<Asset Type="ItemClasses:ContainerData">
<Name>Big Gold Chest</Name>
<DifficultyLevel>Normal</DifficultyLevel>
<IsLocked>true</IsLocked>
<IsTrapped>false</IsTrapped>
<TrapName Null="true" />
<KeyName>Golden Key</KeyName>
<KeyType>Golden Key</KeyType>
<KeysRequired>2</KeysRequired>
<MinGold>500</MinGold>
<MaxGold>750</MaxGold>
<ItemCollection />
</Asset>
</XnaContent>


and my ContainerData class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RpgLibary.SkillClasses;
namespace RpgLibary.ItemClasses
{
public class ContainerData
{
public string Name;
public DifficultyLevel DifficultyLevel;
public bool IsLocked;
public bool IsTrapped;
public string TrapName;
public string KeyName;
public string KeyType;
public int KeysRequired;
public int MinGold;
public int MaxGold;
public Dictionary<string, string> ItemCollection;
public ContainerData()
{
ItemCollection = new Dictionary<string, string>();
}
public override string ToString()
{
string toString = Name + ", ";
toString += DifficultyLevel.ToString() + ", ";
toString += IsLocked.ToString() + ", ";
toString += IsTrapped.ToString() + ", ";
toString += TrapName + ", ";
toString += KeyName + ", ";
toString += KeyType + ", ";
toString += KeysRequired.ToString() + ", ";
toString += MinGold.ToString() + ", ";
toString += MaxGold.ToString();
foreach (KeyValuePair<string, string> pair in ItemCollection)
{
toString += ", " + pair.Key + "+" + pair.Value;
}
return toString;
}
}
}


I have searched up my problem but none seem to relate to me, they say to have the content type in a diffrent project which is what i did.
here is my compile order:
---------------------------------
RpgLibary
rpg
---------------------------------

Thanks for reading if theres any other files you want to look at just ask.
Advertisement
Are you referencing the RpgLibary project in the Content project? Also, you spelled "library" wrong. wink.png

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

The problem is with your Dictionary, which is not a serializable object. I had the same problem a while back, and ended up transferring the data into a List before serializing, much like this:

http://www.dotnetperls.com/convert-dictionary-list

This was not a problem for me because it was during a larger load time, but may hurt performance if it's a regular operation, you'd have to investigate that.

The problem is with your Dictionary, which is not a serializable object. I had the same problem a while back, and ended up transferring the data into a List before serializing, much like this:

http://www.dotnetper...dictionary-list

This was not a problem for me because it was during a larger load time, but may hurt performance if it's a regular operation, you'd have to investigate that.


Thanks for the help. But where would i implement the the ToList function.
When you go to serialize, you would transfer the Dictionary into a List, then serialize the List instead. When you deserialize, you pull the data into a List, then move it into a Dictionary for your game object to use. I don't know your program setup, but this could either be done in the object that is going to be serialized, or in whichever object is handling your serialization.

This topic is closed to new replies.

Advertisement