This has been working for me for weeks I have a custom type which I have been loading from XML and all have worked amazing.
All of a sudden for no Obvious reason I get this error
Microsoft.Xna.Framework.Content.ContentLoadException: ‘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.ReflectiveReader1[[Granulated.Data.Classes.Level, Granulated.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] (Microsoft.Xna.Framework.Content.ReflectiveReader1[[Granulated.Data.Classes.Level, Granulated.Data]]). If you are using trimming, PublishAOT, or targeting mobile platforms, you should call ContentTypeReaderManager.AddTypeCreator() on that reader type somewhere in your code.’
I have google the error and came up with this solution
Granulated.Core.GameClasses.ArrayTypeCreatorHelper.RegisterArrayType();
The internal workings below
using Granulated.Data.Classes;
using Microsoft.Xna.Framework.Content;
using System;
namespace Granulated.Core.GameClasses
{
///
/// Generic array reader that works for any element type T.
///
public class GenericArrayReader : ContentTypeReader<T>
{
protected override T Read(ContentReader input, T existingInstance)
{
// Read array length
int count = input.ReadInt32();
if (count < 0)
throw new InvalidOperationException(“Invalid array length in content data.”);
// Allocate array
T[] array = new T[count];
// Read each element using the correct reader for T
for (int i = 0; i < count; i++)
{
array[i] = input.ReadObject<T>();
}
return array;
}
}
public static class ArrayTypeCreatorHelper
{
/// <summary>
/// Registers a ContentTypeReader for any array type.
/// </summary>
public static void RegisterArrayType<T>()
{
string typeName = typeof(T[]).AssemblyQualifiedName;
// Register the type creator for this array type
ContentTypeReaderManager.AddTypeCreator(
typeName,
() => new GenericArrayReader<T>()
);
}
}
// Example custom typ
// Example ContentTypeReader for MyType
public class MyTypeReader : ContentTypeReader<Level>
{
protected override Level Read(ContentReader input, Level existingInstance)
{
return new Level();
}
}
}
But I still get the error I have no idea what started this issue but its annoying to say the least has o=anyone got any ideas???