Content Load issue on custom type

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???

I’d say try cleaning your solution. Failing that try manually deleting the whole of bin/obj folders (do a backup first), then re-open Visual Studio (reload the project). If it was working before and seemingly randomly has broken (and you didn’t change anything in relation to it), then you probably just have a derped up cache/dependency/something that can be regenned.

@TheKelsam Thanks for your quick reply I tried that to no avail but looking through what I did yesterday I used Github Copilot to profile my code and get the feeling that it may made a project change. Looking round online there alot of posts saying that Is sould have all the content definition. I digging further and once I find solution will post it up. Just bloody annoying as things were going so well.

I have found the issue. Githib Copilot had turned on PublishTrimmed in my project file a bit annoying but removed the lines and everything now works. GitHib CoPilot is a great tool and knows alot about monogame but does make mistakes