Proper way to use IntermediateSerializer with Pipeline Tool

Hi ! I’m currently porting an Xna test game to MonoGame 3.4. Great job : everything works fine with the code, audio, graphics, effects… But i don’t understand how I have to use the Pipeline Tool with my Xml data files.

Under Xna, my Xml data files were compiled with the IntermediateSerializer. Files are built as follows:

<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
  <Asset Type="Geex.Run.Actor[]">
    <Item>
      <Id>1</Id>
      <Name>Furvent</Name>
      <ClassId>1</ClassId>
      <InitialLevel>1</InitialLevel>
      <FinalLevel>99</FinalLevel>

etc.

Under the Pipeline Tool, I can’t compile them. If I try, I get this error:

D:/Code/Geex/git/server/geex-sample/MonoGameGeex/MonoGameGeex/Content/../../../Rm/Data/actors.xml
D:/Code/Geex/git/server/geex-sample/MonoGameGeex/MonoGameGeex/Content/../../../Rm/Data/actors.xml: error: Importer 'XmlImporter' had unexpected failure!
Microsoft.Xna.Framework.Content.Pipeline.InvalidContentException: Could not resolve type 'Geex.Run.Actor[]'.
   at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateReader.ReadObject[T](ContentSerializerAttribute format, ContentTypeSerializer typeSerializer, T existingInstance)
   at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateReader.ReadObject[T](ContentSerializerAttribute format)
   at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateSerializer.Deserialize[T](XmlReader input, String referenceRelocationPath)
   at Microsoft.Xna.Framework.Content.Pipeline.XmlImporter.Import(String filename, ContentImporterContext context)
   at Microsoft.Xna.Framework.Content.Pipeline.ContentImporter`1.Microsoft.Xna.Framework.Content.Pipeline.IContentImporter.Import(String filename, ContentImporterContext context)
   at MonoGame.Framework.Content.Pipeline.Builder.PipelineManager.ProcessContent(PipelineBuildEvent pipelineEvent)

There is indeed no reference to the Geex.Run.Actor class within the pipeline tool. Is there a way to add this reference ? Is their an other way to use IntermediateSerializer with the Pipeline Tool ?

I have read on the update notes that IntermediateSerializer is implemented, but I can’t figure out how to use it.

Select the project node in the treeview and edit the References entry in the property grid to add the reference to your class library that contains the classes for your XML.

Ok thanks, I added the path to the compiled dll library and it works fine… for half the xml files.

For the other files, I got this error:

D:/Code/Geex/git/server/geex-sample/MonoGameGeex/MonoGameGeex/Content/../../../Rm/Data/armors.xml
D:/Code/Geex/git/server/geex-sample/MonoGameGeex/MonoGameGeex/Content/../../../Rm/Data/armors.xml: error: Importer 'XmlImporter' had unexpected failure!
System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Int16.Parse(String s, NumberStyles style, NumberFormatInfo info)
   at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.ElementSerializer`1.Deserialize(IntermediateReader input, List`1 results)
   at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.ListSerializer`1.Deserialize(IntermediateReader input, ContentSerializerAttribute format, List`1 existingInstance)
   at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.ContentTypeSerializer`1.Deserialize(IntermediateReader input, ContentSerializerAttribute format, Object existingInstance)
etc.

Is there a way to have more detail about what is not working on the Intermediate Serializer import ? Some more verbose stacktrace ?

Note: the Intermediate Serializer import for the same file works in a Xna project.

Ok, I have found where is the problem. The MonoGame Intermediate Serializer seems not to accept certain Xml (bad) formats. In my Armor class, I have a List attribute.

  public List<short> GuardElementSet;

In the Intermediate serialized armors.xml files, if this list is empty and if it is formatted as here:

  <GuardElementSet></GuardElementSet>

The monogame content pipeline won’t compile it. If it is more properly formated:

  <GuardElementSet/>

It will works. Same thing for arrays.

Hope this can help. I will report in this topic other format finesses.

There was a fix for this merged to the codebase 5 days ago. It will be in the next release.

Hi,

I’m still working on Intermediate Serializer. A new problem arose: I want to intermediate (de)serialize a class which in the main project of my game, but it is not recognized by the content pipeline. Under Xna I know it was not possible, you had to put the class in a library project, then add a reference toward it in the content project to use intermediate serializer.

Is it still the same in monogame ? No intermediate serializing from class in the project that contains the content pipeline file ?

The content build pipeline still has to have a reference to the assembly containing the type that will be serialized. Generally this means the type must be in a class library that is referenced by both the content build pipeline and the game project. It may be possible to reference the game assembly from the MonoGame content build pipeline, but I have to admit that this is something that I have never tried.

Ok, for now I’ll use the class library technique.

I have found what seems to be a difference between Xna and Monogame. It is about deserializing multidimentionnal arrays. Maybe i’m missing something.

I got a simple class I want to serialize with a byte[][] array.

    public class Mask
    {
        public byte[][] array;
    }

Under Xna, I serialized it as:

<?xml version="1.0" encoding="utf-8"?>
<XnaContent>
  <Asset Type="Workshop01.Custom.Mask">
    <array>
      <Item>1 1 1</Item>
      <Item>1 1 1</Item>
    </array>
  </Asset>
</XnaContent>

And it was OK. But the monogame content pipeline does not accept it and gives me this error:

D:/[...]/workshop01/Workshop01/Content/Data/mask.xml: error: Importer 'XmlImporter' had unexpected failure!
Microsoft.Xna.Framework.Content.Pipeline.InvalidContentException: An error occured parsing. ---> System.Xml.XmlException: 'Element' est un XmlNodeType non valide. Ligne 6, position 8.
   … System.Xml.XmlReader.ReadEndElement()
   … Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateReader.ReadRawObject[T](ContentSerializerAttribute format, ContentTypeSerializer typeSerializer, T existingInstance)
   … Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateReader.ReadObject[T](ContentSerializerAttribute format, ContentTypeSerializer typeSerializer, T existingInstance)
   … Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateReader.ReadObject[T](ContentSerializerAttribute format)
   … Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateSerializer.Deserialize[T](XmlReader input, String referenceRelocationPath)

   --- Fin de la trace de la pile d'exception interne ---
   … Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateSerializer.Deserialize[T](XmlReader input, String referenceRelocationPath)
   … Microsoft.Xna.Framework.Content.Pipeline.XmlImporter.Import(String filename, ContentImporterContext context)
   … Microsoft.Xna.Framework.Content.Pipeline.ContentImporter`1.Microsoft.Xna.Framework.Content.Pipeline.IContentImporter.Import(String filename, ContentImporterContext context)
   … MonoGame.Framework.Content.Pipeline.Builder.PipelineManager.ProcessContent(PipelineBuildEvent pipelineEvent)

Lign 6 position 8 is the start of the second <Item>. It seems the </Item> is not accepted, so the second has no sense but I don’t know what to do about that. Is there an other way to serialize/deserialize multidimentionnal arrays ? Am I missing something ?

(The same question stands for int[][][] arrays.)

The IntermediateSerializer is one of the more complex content reader/writers. There are many forms of data representation in the XML files, and this may be one that is not yet supported. It shouldn’t be difficult to add. It just takes time and someone to do it.

Ok. Could you head me toward a place/topic where i can start learning about the monogame version of the Intermediate Serializer ? I’ll need the multidimensional array Intermediate serialization for my game and, if I can solve this problem, it would be a pleasure to contribute to the monogame community.

Sent the source to an other computer, recompiled, and now seems to work. I don’t understand oO