[Solved] Custom ContentTypeReader exception

Hi,
I’m having a problem loading an asset of a custom content type exported by the monogame pipeline tool.
These are the steps that I followed:

  1. Converted the SpriteSheetPipeline processor to work with monogame

  2. Added compiled library to MonoGame Pipeline

  3. Added assets in MonoGame Pipeline

  4. Changed the assets’ processor to SpriteSheetPipeline

  5. When loading them in the game I get the following exception:

    Could not find ContentTypeReader Type. Please ensure the name of the Assembly that contains the Type matches the assembly in the full type name: Microsoft.Xna.Framework.Content.ArrayReader1[[Microsoft.Xna.Framework.Content.Pipeline.Graphics.Texture2DContent, MonoGame.Framework.Content.Pipeline, Version=3.4.0.456, Culture=neutral, PublicKeyToken=null]] (Microsoft.Xna.Framework.Content.ArrayReader1[[Microsoft.Xna.Framework.Content.Pipeline.Graphics.Texture2DContent, MonoGame.Framework.Content.Pipeline]])

It doesn’t feel like it’s pointing to my code so I’m not sure what I’m missing here.
Can someone point me out in the right direction to fix this issue?

Thank you,
Ricardo.

The game project does not reference the content pipeline, so it cannot load an array of Texture2DContent. I think there are some fixes required in the ContentWriter part of the content pipeline extension.

Can you show the code for the SpriteSheetPipeline? It will likely need the GetRuntimeType and GetRuntimeReader methods of the ContentTypeWriter overridden to specify the runtime types.

Sure, here’s the code: http://n0n4m3.codingcorner.net/SpriteSheetPipeline.zip
It is mostly based on the XNA Sample by Microsoft.
Thank you!

With those methods overridden I get a cast exception when reading the asset:
spriteSheet.textures = input.ReadObject<Texture2D[]>();

produces:
Additional information: Unable to cast object of type ‘Microsoft.Xna.Framework.Graphics.Texture2D’ to type ‘Microsoft.Xna.Framework.Content.Pipeline.Graphics.Texture2DContent’.

How should I read the Texture2DContent?

I was able to fix the problem by writing a count and each texture separately and have the reader do the reverse, read the count, instantiate the array of texture2d and read each texture2d to that array.

It seems like writing an array of textures is not supported out of the box.

This error seems like one caused by an issue I fixed some time back but the fix is still waiting to be merged. I’m not sure but it would be interesting to see if your original code works ok once this change set is applied (I can’t test it for a few days): Xml compile and load fails: Empty list of custom type containing an enum by Aranda · Pull Request #3923 · MonoGame/MonoGame · GitHub

There are some problems with the current content pipeline build where it doesn’t always get all the required content reader types (particularly for generic types or arrays) written into the Xnb files.