0

I have a question concerning an Error I experience while trying to read an XML-File through the XNA 4.0 Content Pipeline in order to build Objects. First I reused old XNA 3.1 Code of mine which worked back in the day but now throws the an Error Message:

Building content threw InvalidOperationException: Instanzen von abstrakten Klassen können nicht erstellt werden. (Unable to build Instances of abstract Classes - roughly translated) at ReflectionEmitUtils() ...and goes on forever, I can post it, if it's needed, but for better readability of my initial request..

Then I used this Method but it throws the same error.

These are the relevant pieces of source code: I've written a class to define the content/structure of the XML-File:

public class Command
    {        
        public List<bool> mButtons;       
        public List<Keys> keys;        
        public Enum iD;       
    }

And this is my XML File, with which I want to build Command-Objects

<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
  <Asset Type="KinectRTS_Input.Command">
    <mButtons>true/mButtons>
    <keys>
      <Item>LeftControl/Item>      
    </keys>
    <iD>SMulti/iD>
  </Asset>
</XnaContent>

(In my code, the Brackets are all correct, though since this Form processes XML-Tags...;)) I used a Test-Application in order to find out, which Format the XNA-Serializer uses to output List-Items and enums, so I'm reasonably sure, that there's not the error.

robert
  • 33,242
  • 8
  • 53
  • 74

2 Answers2

0

It looks like either your XML is invalid or your Model is. For the mButtons field, you have defined it as a List<bool> but in the XML it's a bool not a List<bool>. I would either edit the XML to have the <mButtons> element contain a single <Item> element or change the declaration of mButtons in the Model to be a bool not List<bool>.

borrillis
  • 656
  • 4
  • 7
0

Too easy...the problem wasn't with the Lists, in fact the Test-Application mentioned in my request actually returned XML-Tags with Item-Tags for the keys-List and without Item-Tags for the bool-list. Wrapping the bool into Item-Tags resulted in an " at not expected"-Error. I have no idea, why the Serializer handles List and List differently, though.

The problem was the Enum 'iD', which is an abstract class and thus throws the Error mentiones above. It seems that I was overwhelmed by the sheer size of the error-message and just disregarded the crucial bit of info - that the Serializer tries to build an abstract class.

But thanks anyway. – Kuroni Kaimei