Jump to content
  • Advertisement
Sign in to follow this  
Thekill473

Need help Xna Xml Deserializing

This topic is 2507 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!