Unable to load one or more of the requested types

I should preface this by saying I’m new to MonoGame and programming in general.
I want to store the data for the levels in my game as XML files in the Content Pipeline. Currently, all my classes are inside of one Project. The XML file I’m trying to load is the following:

<?xml version="1.0"?>
<XnaContent xmlns:ns="Microsoft.Xna.Framework">
	<Asset Type="NotAGame.Room">
		<tileSet>
		<Tile>
		  <SpriteID>brick</SpriteID>
		  <Position>
			<X>64</X>
			<Y>0</Y>
		  </Position>
		  <isSolid>true</isSolid>
		  <collisionMask>
			<X>0</X>
			<Y>0</Y>
			<Width>32</Width>
			<Height>32</Height>
			<Location>
			  <X>0</X>
			  <Y>0</Y>
			</Location>
			<Size>
			  <X>32</X>
			  <Y>32</Y>
			</Size>
		  </collisionMask>
		</Tile>
		<Tile>
		  <SpriteID>brick</SpriteID>
		  <Position>
			<X>32</X>
			<Y>0</Y>
		  </Position>
		  <isSolid>true</isSolid>
		  <collisionMask>
			<X>32</X>
			<Y>0</Y>
			<Width>32</Width>
			<Height>32</Height>
			<Location>
			  <X>32</X>
			  <Y>0</Y>
			</Location>
			<Size>
			  <X>32</X>
			  <Y>32</Y>
			</Size>
		  </collisionMask>
		</Tile>
		<Tile>
		  <SpriteID>brick</SpriteID>
		  <Position>
			<X>0</X>
			<Y>32</Y>
		  </Position>
		  <isSolid>true</isSolid>
		  <collisionMask>
			<X>0</X>
			<Y>32</Y>
			<Width>32</Width>
			<Height>32</Height>
			<Location>
			  <X>0</X>
			  <Y>32</Y>
			</Location>
			<Size>
			  <X>32</X>
			  <Y>32</Y>
			</Size>
		  </collisionMask>
		</Tile>
	  </tileSet>
	  <randomMovingNpcs>
		<RandomMovingNPC>
		  <SpriteID>orb</SpriteID>
		  <Position>
			<X>32</X>
			<Y>32</Y>
		  </Position>
		  <isSolid>true</isSolid>
		  <collisionMask>
			<X>32</X>
			<Y>32</Y>
			<Width>32</Width>
			<Height>32</Height>
			<Location>
			  <X>32</X>
			  <Y>32</Y>
			</Location>
			<Size>
			  <X>32</X>
			  <Y>32</Y>
			</Size>
		  </collisionMask>
		  <originPosition>
			<X>32</X>
			<Y>32</Y>
		  </originPosition>
		  <velocity>
			<X>0</X>
			<Y>0</Y>
		  </velocity>
		  <maxDistance>64</maxDistance>
		  <movement>
			<X>0</X>
			<Y>0</Y>
		  </movement>
		  <timer>92</timer>
		</RandomMovingNPC>
	  </randomMovingNpcs>
	  <player>
		<SpriteID>security_agent</SpriteID>
		<Position>
		  <X>112</X>
		  <Y>134</Y>
		</Position>
		<isSolid>true</isSolid>
		<collisionMask>
		  <X>112</X>
		  <Y>134</Y>
		  <Width>32</Width>
		  <Height>32</Height>
		  <Location>
			<X>112</X>
			<Y>134</Y>
		  </Location>
		  <Size>
			<X>32</X>
			<Y>32</Y>
		  </Size>
		</collisionMask>
		<Velocity>
		  <X>0</X>
		  <Y>0</Y>
		</Velocity>
	  </player>
	  <camera2d>
		<matrix>
		  <M11>2</M11>
		  <M12>0</M12>
		  <M13>0</M13>
		  <M14>0</M14>
		  <M21>0</M21>
		  <M22>2</M22>
		  <M23>0</M23>
		  <M24>0</M24>
		  <M31>0</M31>
		  <M32>0</M32>
		  <M33>2</M33>
		  <M34>0</M34>
		  <M41>0</M41>
		  <M42>0</M42>
		  <M43>0</M43>
		  <M44>1</M44>
		  <Backward>
			<X>0</X>
			<Y>0</Y>
			<Z>2</Z>
		  </Backward>
		  <Down>
			<X>-0</X>
			<Y>-2</Y>
			<Z>-0</Z>
		  </Down>
		  <Forward>
			<X>-0</X>
			<Y>-0</Y>
			<Z>-2</Z>
		  </Forward>
		  <Left>
			<X>-2</X>
			<Y>-0</Y>
			<Z>-0</Z>
		  </Left>
		  <Right>
			<X>2</X>
			<Y>0</Y>
			<Z>0</Z>
		  </Right>
		  <Translation>
			<X>0</X>
			<Y>0</Y>
			<Z>0</Z>
		  </Translation>
		  <Up>
			<X>0</X>
			<Y>2</Y>
			<Z>0</Z>
		  </Up>
		</matrix>
		<position>
		  <X>0</X>
		  <Y>0</Y>
		</position>
		<zoom>2</zoom>
		<size>
		  <X>0</X>
		  <Y>0</Y>
		</size>
	  </camera2d>
	</Asset>
</XnaContent>

Currently, when I try to run the game, I get the following error: “Unable to load one or more of the requested types. Retrieve the Loader.Exceptions property for more information”.
The XML file was created by serializing an instance I created through code using an XmlSerializer. I’m completely stumped… I’ve tried referencing the Monogame.Framework.Content.Pipeline.dll but that didn’t work.


Add a support library type project (that creates a .dll) and move your Room class there.
Than you can reference that .dll from your game project to use that Room and more importantly you can reference it from the content pipeline.
It should than build fine (unless other errors, for example the parameters are not in same order as they are defined in class).
I’m not sure if there’s a way to do it without the supporting library tho.

1 Like

Thanks for the reply. Unfortunately, even after successfully creating and referencing a class library with all my classes, I’m still getting the same error. I did change the Room class a bit and generated a new instance to serialize, which is the one that is in the Content now.
To clarify, I’m supposed to build the class library with all the classes, reference it in the Game instead of just having the classes in the same project, and then reference the library in the Game’s Content through the Content Pipeline tool, right?

I’ve never used the xmlimporter with anything complex but I think your array/list items should be <item></item> (instead of <RandomMovingNPC> and <tile> (if TileSet is a collection)).
Take a look here: https://blogs.msdn.microsoft.com/shawnhar/2008/08/12/everything-you-ever-wanted-to-know-about-intermediateserializer/ it should still hold true since MonoGame is trying very hard to be XNA compatible.
As to the structure of the library/references: picture example

Even after replacing the class types with Item for the items inside Lists, I’m getting the same error… Maybe if I serialize the instance with the IntermediateSerializer, it’ll build correctly in the content. Currently, I’m doing it like this:

XmlSerializer xmlSerializer = new XmlSerializer(typeof(Room));
FileStream roomXml = File.Create("C:/Users/Alexandre/Desktop/room00.xml");
xmlSerializer.Serialize(roomXml, currentRoom);
roomXml.Dispose();

The problem is even if I try to use the IntermediateSerializer with an XmlWriter instead of an XmlSerializer, I just can’t access IntermediateSerializer. I have added a reference to the MonoGame.Framework.Content.Pipeline.dll in the main Game project but that doesn’t seem to make it accessible.

As far as my knowledge goes, you’ll have to write the extension for the Content Pipeline in order to load and process custom XML, or deserialize XML without using Content Pipeline. Content Pipeline’s default XML importer (again, as far as my knowledge goes) doesn’t support much aside from basic things like collections, MonoGame’s structures like Rectangle etc.

This is a good set of tutorials for Content Pipeline, despite being for XNA: http://rbwhitaker.wikidot.com/content-pipeline-tutorials