6

I am currently trying to port a game I am working on from XNA to Monogame, but I am having some trouble getting the content pipeline to cooperate. My game uses a number of XML files as XNB assets to represent objects in the game, which I created following the instructions here. However, trying to move this across word-for-word into Monogame produces the following error:

An unhandled exception of type 'Microsoft.Xna.Framework.Content.ContentLoadException' occurred in MonoGame.Framework.dll

Additional information: Could not load Parts\Window.xnb asset as a non-content file!

Here is the class I have been using to define the content of the XML files:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace FileTypes
{
    public class PartFile
    {
        public struct State
        {
            public Rectangle[] frames;
            public int[] collision;
        }

        public Vector2 size;
        public string image;
        public string defaultState = "default";
        public bool fillBG;
        public int ticksPerFrame;
        public Dictionary<string, State> states;
        public string[] modules;
    }
}

Here is one of the XML files in the project:

<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
  <Asset Type="FileTypes.PartFile">
    <size>2 3</size>
    <image>Computer</image>
    <defaultState>default</defaultState>
    <fillBG>false</fillBG>
    <ticksPerFrame>7</ticksPerFrame>
    <states>
      <Item>
        <Key>default</Key>
        <Value>
          <frames>
            0 0 40 60
            40 0 40 60
          </frames>
          <collision>
            0 0
            0 0
            0 0
          </collision>
        </Value>
      </Item>
      <Item>
        <Key>active</Key>
        <Value>
          <frames>
            80 0 40 60
            120 0 40 60
          </frames>
          <collision>
            0 0
            0 0
            0 0
          </collision>
        </Value>
      </Item>
    </states>
    <modules>
      <Item>testModule</Item>
    </modules>
  </Asset>
</XnaContent>

And finally here is a sample of the code I use to load the file:

FileTypes.PartFile srcPart = content.Load<FileTypes.PartFile>("Parts\\" + name);

Does anybody know what I need to do in order to get my code working in Monogame? I've been looking around the internet for a fair while, but so far I've yet to find a solution to my issue. Alternatively, if I've been going about the entire system wrong all this time and there's a far easier way to handle what I want to do, I'd love to hear it.

Thanks in advance!

Community
  • 1
  • 1
Hunter X
  • 61
  • 1
  • 2

4 Answers4

5

I wrote a rather long tutorial about loading custom content with the MonoGame Pipeline. Here's the summary

  1. Create a new project to hold your content importer, processor and writer
  2. Create the content importer
  3. Create the content processor
  4. Create the content type writer
  5. Create the content type reader
  6. Reference the DLL from the Pipeline tool
  7. Read the content into your game

Creating the importer, processor, reader and writer is the same as XNA. You can refer to the MSDN documentation for that.

The tricky part is getting your DLL to work with the Pipeline tool. To add it as a reference look for the the References property of the root tree node.

craftworkgames
  • 9,437
  • 4
  • 41
  • 52
0

Unless I'm mistaken, you need to set the build action of the file to "Content" and the copy to output directory to "copy if newer" in the properties tab for the file

Nico
  • 94
  • 9
  • I've done this and it still doesn't work I'm afraid. – Hunter X Feb 20 '14 at 14:10
  • oops, just looked into the links you posted (I've never used xml for content pipeline data), and I doubt you can do that in monogame, as it does not have a content pipeline, and so it cant convert the xml into xnb files, your better off to build the files in xna and just copy the xnb files in to your monogame project and do the above ^ to them – Nico Feb 21 '14 at 01:53
0

Content.Load<T> uses Microsoft.Xna.Framework.Content.Pipeline.IntermediateSerializer for an xml. Monogame doesn't support Microsoft.Xna.Framework.Content.Pipeline. It means you cannot deserialize an intermediate xml.

Wallstrider
  • 856
  • 1
  • 7
  • 22
0

Monogame comes with content processors for XML. Open up the content pipeline app and add an XML file; you will see it has the importer XmlImporter and processor PassThroughProcessor.

Take a look at @craftworkgames excellent tutorials for how to extend the behaviour.

sdgfsdh
  • 33,689
  • 26
  • 132
  • 245