Can't load XML through content pipeline "An error occured parsing." No details

Hi, thanks for reading! I’m trying to load an xml file through the content pipeline, but it throws the following comletely useless error when I try to build the content project:

[FilePath]/TestLevel.xml(7,6): An error occured parsing.

There’s no detail about what is failing. Is the 7,6 a line and character number? Is there any way I can get more info about what failed?

I have the XnaContent node and the Asset node with the type. I’ve got a reference to my class library in the content project references. The xml file passes validation. I already fixed some issues with multi-dimensional rays in my class. What else can I look for?

Thanks for your help!

Hi @12StringSamurai,

Welcome to the community! It looks like a line/column combination. Can you share line 7? Something you can look at is strings where numbers are expected.

1 Like

Hi @ Synammon, thanks for replying! I made new classes with much less going on in them to see if that would be easier to deserialize. I now have an array of objects that’s just integers and a string. I still get the same “An error occured parsing” but now on (5,6).

Here’s the XML:

 <?xml version="1.0" encoding="utf-8"?>
    <XnaContent xmlns:ns="Microsoft.Xna.Framework">
    <Asset Type="JPPGameFramework.LevelXML">
    <LevelObjects>
        <SpriteCharacterXML>
          <MapX>0</MapX>
          <MapY>980</MapY>
          <OriginX>0</OriginX>
          <OriginY>0</OriginY>      	  
          <Height>100</Height>
          <Width>500</Width>
          <NumCols>1</NumCols>
          <NumRows>1</NumRows>
          <IsInOrNearCamera>true</IsInOrNearCamera>
          <IsPlatform>true</IsPlatform>
          <SpriteSheetName>floor1</SpriteSheetName>      
        </SpriteCharacterXML>   
    </LevelObjects>
    </Asset>
    </XnaContent>

Level XML is just an array of SpriteCharacterXML objects:
public class SpriteCharacterXML
{
public int MapX {get; set;}
public int MapY { get; set; }
public int OriginX { get; set; }
public int OriginY { get; set; }
public int Height { get; set; }
public int Weight { get; set; }
public int NumRows { get; set; }
public int NumCols { get; set; }
public bool IsPlatform { get; set; }

public string SpriteSheetName { get; set; }

}

There’s not really anything exciting going on here. I wonder what the heck it could be. Thanks again for your help!

I don’t see IsInOrNearCamera in your class. Is that just a copy/paste issue? Other than that I’m not seeing anything obvious wrong with the XML or the class. Are you using a single dimensional array or a two dimensional array?

Oops, I did forget to remove IsInOrNearCamera from the xml. Good observation! So there was a property in the xml that was not in the class. Unfortunately, removing it still leaves me with the same “An error occured parsing (5,6)” message.

I am using a single dimension array. Hrm.

Can you share your serialization code?

Sorry, I didn’t see this until today.

I wrote the xml by hand, I didn’t serialize it, I used the Add -> New Item -> Xml Content option in the MGCB editor. That gave me an xml file with the correct XML version and XNAContent and Asset nodes. I filled the rest out by hand.

After I saw your post just now, I tried to use the techniques described on these two pages to serialize xml from an instantiated object in my code:
When I try this method:
http://www.shawnhargreaves.com/blog/teaching-a-man-to-fish.html

When I try to use this:
Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateSerializer.Serialize

It can’t find the Pipeline class.

How do you serialize xml in monogame, @Synammon? Thanks for your helpful suggestions!

You need to add the NuGet package for MonoGame.Framework.Content to your solution. I’m on my phone so it might be MonoGame.Framework.Content.Pipeline. If you’re using 3.7.1 you need to reference a DLL. I can’t recall the path off the top of my head.

EDIT
The location of the MonoGame.Framework.Content.Pipeline.dll for 3.7.1 is below.
C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools\

1 Like

I GOT IT TO WORK! Thanks so much for your suggestion, @Synammon. Neither of the articles I found mentioned the need to add a Nuget package to serialize XML. Also, the XML file that the Add → New Item → Xml Content option in the MGCB editor generated had the XnaContent and Asset notes setup incorrectly.

XML serialized by the IntermediateSerializer looks like this:

< XnaContent xmlns:JPPGameFramework=“JPPGameFramework”>
< Asset Type=“JPPGameFramework:LevelXML”>

XML from the MGCB editor looks like this:

< XnaContent xmlns:ns=“Microsoft.Xna.Framework”>
< Asset Type=“JPPGameFramework.LevelXML”>

When I import the serialized XML I can actually read it in using Content.Load.

I couldn’t have done it without you!

1 Like

??

Sorry @MrValentine, there was a typo and the text editor here didn’t display my XML. I’ve fixed the post.

1 Like