1
\$\begingroup\$

I have an XML file that I'm trying to import into my MonoGame project using the content pipeline. I'm having trouble getting the MonoGame Pipeline tool to convert the XML file into a .xnb file before I can even run the program.

The XML file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<XnaContent>
  <Asset Type="GameObjects.ObjectInstruction">
    <FrameNames>
      <Item>Image_1</Item>
      <Item>Image_2</Item>
    </FrameNames>
    <FrameSpeed>10</FrameSpeed>
    <HorizontalOrigin>0.5</HorizontalOrigin>
    <VerticalOrigin>0.5</VerticalOrigin>
    <HorizontalScaling>1</HorizontalScaling>
    <VerticalScaling>1</VerticalScaling>
    <HorizontalOffset>0</HorizontalOffset>
    <VerticalOffset>0</VerticalOffset>
    <Subset Null="true" />
    <RotationRadians>0</RotationRadians>
    <Tint>
      <B>255</B>
      <G>255</G>
      <R>255</R>
      <A>255</A>
      <PackedValue>4294967295</PackedValue>
    </Tint>
  </Asset>
</XnaContent>

The GameObjects namespace is in a Visual Studio project that creates a .dll file, and I have another MonoGame project that references GameObjects and is the one in which I'm trying to do all the content stuff.

Inside the Pipeline tool I've got a reference set to the GameObjects.dll file. This file shows up in several places, and if I pick the wrong one the Pipeline tool fails with the error "Assembly is either corrupt or built using a different target platform than this process. Reference another target architecture (x86, x64, AnyCPU, etc.) of this assembly."

If I change the reference to the .dll file in the GameObjects project folder, the Pipeline tool still fails when trying to process my XML file. The error message looks like "System.Xml.XmlException: 'Element' is an invalid XmlNodeType. Line 19, position 8." This part of the XML file would be the G field of the Tint part of the ObjectInstruction object (Tint is a Color).

I've been knocking my head against this problem and getting nowhere. How do I use the Monogame Pipeline tool with XML files? How do I get it to recognize the definition of ObjectInstruction and process the XML file into a .xnb file? I'm pretty sure the rest of my program will run if I can solve this bit. Thanks for any help.

\$\endgroup\$
0
\$\begingroup\$

Since Tint is a Color, you should try replacing the node with just

<Tint>FFFFFFFF</Tint>

MonoGame XML serializer understands this shorthand form.

There is a way you can use to create correct XML files for reference: see this blog post. Of course, you should reference the matching MonoGame DLL (located at %ProgramFilesX86%\MSBuild\MonoGame\v3.0\Tools).

The assembly reference error you mentioned is caused by the Pipeline being 64-bit only, so you need to use the x64 assembly.

\$\endgroup\$
0
\$\begingroup\$

Petri Laarne had the fix to the problem, but I thought I'd follow up with some lessons learned in case anyone else has a similar issue.

I generated the above XML file by writing a program to create a dummy version of my object and then export it using IntermediateSerializer. For whatever reason, the MonoGame version of this class output the Color struct in the form above, with all the fields broken out. (According to what I've read, this is consistent with XMLSerializer. I don't have enough insight into this topic to say why the output is what it is.) My problem stemmed from the fact that the XML importer was expecting a different format for the Color field than what I had in my test file.

According to this link, the IntermediateSerializer can read a Color struct with an 8-digit hexadecimal code. That article also had some notes on the Rectangle struct that was giving me similar problems in another XML file.

In summary, check that you're using the right XML format and linking the MonoGame Pipeline tool to the correct definition for the class you're trying to serialize.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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