XNA 4.0: Problem with loading XML content files
Posted
by
200
on Game Development
See other posts from Game Development
or by 200
Published on 2012-11-07T14:57:31Z
Indexed on
2012/11/07
17:19 UTC
Read the original article
Hit count: 419
I'm new to XNA so hopefully my question isn't too silly. I'm trying to load content data from XML.
My XML file is placed in my Content project (the new XNA 4 thing), called "Event1.xml":
<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<Asset Type="MyNamespace.Event"> // error on this line
<name>1</name>
</Asset>
</XnaContent>
My "Event" class is placed in my main project:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace MyNamespace
{
public class Event
{
public string name;
}
}
The XML file is being called by my main game class inside the LoadContent() method:
Event temp = Content.Load<Event>("Event1");
And this is the error I'm getting:
There was an error while deserializing intermediate XML. Cannot find type "MyNamespace.Event"
I think the problem is because at the time the XML is being evaluated, the Event class has not been established because one file is in my main project while the other is in my Content project (being a XNA 4.0 project and such).
I have also tried changing the build action of the xml file from compile to content; however the program would then not be able to find the file and would give this other warning:
Project item 'Event1.xml' was not built with the XNA Framework Content Pipeline. Set its Build Action property to Compile to build it.
Any suggestions are appreciated. Thanks.
© Game Development or respective owner