Importer 'XmlImporter' had unexpected failure

I am trying to import the following xml file (for the Curve class).

<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:Framework="Microsoft.Xna.Framework">
  <Asset Type="Framework:Curve">
    <PreLoop>Constant</PreLoop>
    <PostLoop>Constant</PostLoop>
    <Keys>-4.5 230 0 0 Smooth 0.61 230 0 0 Smooth 77 0 0 0 Smooth 191 0 0 0 Smooth 234.606 61.751 165.362167 64.63784 Smooth 251.651 230 0 0 Smooth</Keys>
  </Asset>
</XnaContent>

I get the error:

error: Importer ‘XmlImporter’ had unexpected failure!
Microsoft.Xna.Framework.Content.Pipeline.InvalidContentException: The Xml element Keys is required!
ved Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.ReflectiveSerializer.Deserialize(IntermediateReader input, ContentSerializerAttribute format, Object existingInstance)
ved Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateReader.ReadRawObject[T](ContentSerializerAttribute format, ContentTypeSerializer typeSerializer, T existingInstance)
ved Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateReader.ReadObject[T](ContentSerializerAttribute format, ContentTypeSerializer typeSerializer, T existingInstance)
ved Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateReader.ReadObject[T](ContentSerializerAttribute format)
ved Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateSerializer.Deserialize[T](XmlReader input, String referenceRelocationPath)
ved Microsoft.Xna.Framework.Content.Pipeline.XmlImporter.Import(String filename, ContentImporterContext context)
ved Microsoft.Xna.Framework.Content.Pipeline.ContentImporter`1.Microsoft.Xna.Framework.Content.Pipeline.IContentImporter.Import(String filename, ContentImporterContext context)
ved MonoGame.Framework.Content.Pipeline.Builder.PipelineManager.ProcessContent(PipelineBuildEvent pipelineEvent)

This is what the Keys property looks like in the XNA Curve class:

public CurveKeyCollection Keys { get; }

CurveKeyCollection contains this property:

public CurveKey this[int index] { get; set; }

These are the 5 properties in CurveKey class:

    public CurveContinuity Continuity { get; set; }    
    public float Position { get; }   
    public float TangentIn { get; set; }   
    public float TangentOut { get; set; }     
    public float Value { get; set; }

This is what it apparently fails to deserialize… is it because some of the properties only have a public setter, but not a public getter?

The Keys you have looks like a ToString() output to me - I’m not great on XML (still getting to the grips of it) but you might need to break it down into the actual properties. (brackets removed - not sure how to display angle brackets) - When I mess with XML I just serialize and deserialize my class - not used monogame yet. Hope this helps.

Keys
	CurveKey
		Position VALUE /Position
		TangentIn VALUE /TangentIn
		TangentOut VALUE /TangentOut
		Value VALUE /Value
		Continuity
			Property1 VALUE /Property1
			Property2 VALUE /Property2
		/Continuity
	/CurveKey
	CurveKey
		...
	/CurveKey
/Keys

That might be a useful workaround. You can display brackets by clicking Preformatted text in the editor.

This used to work in XNA. Could it be a MonoGame bug?

I changed the file to use standard tags instead of the shorthand. I get the same error though.

<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:Framework="Microsoft.Xna.Framework">
  <Asset Type="Framework:Curve">
    <PreLoop>Constant</PreLoop>
    <PostLoop>Constant</PostLoop>
    <Keys>
      <!-- float position, float value, float tangentIn, float tangentOut, CurveContinuity continuity -->
      <CurveKey>     
        <Position>-4.5</Position>
        <Value>230</Value>
        <TangentIn>0</TangentIn>
        <TangentOut>0</TangentOut>
        <Continuity>Smooth</Continuity>         
      </CurveKey>
      <CurveKey>
        <Position>0.61</Position>
        <Value>230</Value>
        <TangentIn>0</TangentIn>
        <TangentOut>0</TangentOut>
        <Continuity>Smooth</Continuity>
      </CurveKey>
      <CurveKey>
        <Position>77</Position>
        <Value>0</Value>
        <TangentIn>0</TangentIn>
        <TangentOut>0</TangentOut>
        <Continuity>Smooth</Continuity>
      </CurveKey>
      <CurveKey>
        <Position>191</Position>
        <Value>0</Value>
        <TangentIn>0</TangentIn>
        <TangentOut>0</TangentOut>
        <Continuity>Smooth</Continuity>
      </CurveKey>
      <CurveKey>
        <Position>234.606</Position>
        <Value>61.751</Value>
        <TangentIn>165.362167</TangentIn>
        <TangentOut>64.63784</TangentOut>
        <Continuity>Smooth</Continuity>
      </CurveKey>
      <CurveKey>
        <Position>251.651</Position>
        <Value>230</Value>
        <TangentIn>0</TangentIn>
        <TangentOut>0</TangentOut>
        <Continuity>Smooth</Continuity>
      </CurveKey>
    </Keys>
  </Asset>
</XnaContent>

Got this problem too…

How to set the type property of the asset tag ?
is this

namespace.class
or namespace:class

ie:

XMLTest.MyTest
XMLTest:MyTest

from https://msdn.microsoft.com/en-us/library/ff604978(v=xnagamestudio.40).aspx

When I was last playing around with it my xml is declared like:

<?xml version="1.0" encoding="utf-8"?> <XnaContent xmlns:ns="Microsoft.Xna.Framework"> <Asset Type="System.Collections.Generic.List[Ballz.Shared.Entities.HistoryRegion]"> <Item><Key>1</Key><X>35</X><Y>32</Y><Color>FFFFFFFF</Color></Item> <Item><Key>2</Key><X>32</X><Y>62</Y><Color>FFFFFFFF</Color></Item> <Item><Key>3</Key><X>67</X><Y>45</Y><Color>FFFFFFFF</Color></Item> </Asset> </XnaContent>

the C# class for the above is below.

Hope this helps.

namespace Ballz.Shared.Entities
{
	[Serializable]
	public class HistoryRegion
	{
		public string Key;
		public int X;
		public int Y;

		[XmlElement("Color")]
		public Color Color;

		[XmlIgnore]
		public string test { get; private set; }

		public HistoryRegion()
		{
		}

		public HistoryRegion(string key, int x, int y, Color regionColor)
		{
			Key = key;
			X = x;
			Y = y;
			Color = regionColor;
		}
	}
}

Ain’t the value in xmlns should be “Ballz.Shared.Entities” ?

Good question, not sure, will have to test that - but it seems to work with it set as it is.

xmlns:ns=“Microsoft.Xna.Framework”

Id line to understand when this is the ine to use and when i have to put the namespace of the class filled with it