Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

This is a typical scenario. You must create a 3rd project and place your event class in it. Set the other 2 projects to depend on it so it builds first. Set a reference to the 3rd project in the other 2 projects.

share|improve this answer
    
Thanks Steve. I created a third project in the solution, added it to the references of the two existing projects and moved the Event class over to the new project - everything's working now, thanks! :) –  S200 Nov 7 '12 at 17:46
add comment

Agree with Steve H. Just make a third project called Resources or DataTypes or something along those lines, and add the reference in your other projects to it, as Steve said. Put your Event object in that new project, and make the XML file Compile for its build action.

share|improve this answer
    
Thanks, it's working now :) –  S200 Nov 7 '12 at 17:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.