ContentManager error

Before that, it worked fine until I moved the SpriteMap class to another folder. How can I debug this error? Thank you in advance for the answer.

as it breaks on that line, we can safely assume, that “input” is not null, but “ContentManager” is null.

so somewhere you do not set a reference somewhere, and as we don’t know what “input” is we may not be able to help any further

public class TilesetReader : ContentTypeReader<Tileset>
    {
        protected override Tileset Read(ContentReader input, Tileset existingInstance)
        {
            var count = input.ReadInt32();

            List<Tile> tiles = new List<Tile>();

            for (int i = 0; i < count; i++)
            {
                tiles.Add(ReadTile(input));
            }

            return new Tileset(tiles);
        }

        private Tile ReadTile(ContentReader input)
        {
            var isRuled = input.ReadBoolean();

            List<TileRule> tileRules = null;

            if (isRuled)
            {
                var countRules = input.ReadInt32();
                tileRules = new List<TileRule>();

                for (int i = 0; i < countRules; i++)
                {
                    var neighbors = input.ReadObject<Dictionary<Point, TileRulePointType>>();
                    var tile = ReadTile(input);
                    tileRules.Add(new TileRule(neighbors, tile));
                }

            }

            var mapId = input.ReadString();
            var spriteId = input.ReadInt32();
            var color = input.ReadColor();
            var effect = input.ReadInt32();
            var collider = input.ReadInt32();

            var map = input.ContentManager.Load<SpriteMap>(mapId); // error
            Sprite sprite = map.Sprites[spriteId];

The error occurs in the ContentManager itself. There are no null links at all.

You are reading an object from inside a reader. That is not supported.
Perhaps you want to call context.ReadExternalReference() here?

What are you writing in the ContentWriter after the colliders?
The reader must read exactly what the writer writes.

You see, it all worked before changing the namespace of the SpriteMap class. When I write a Tileset object, I write the path to SpriteMap (string type).

[ContentTypeWriter]
    public class TilesetWriter : ContentTypeWriter<Tileset>
    {
        public override string GetRuntimeType(TargetPlatform targetPlatform)
        {
            return typeof(TilesetReader).AssemblyQualifiedName;
        }

        public override string GetRuntimeReader(TargetPlatform targetPlatform)
        {
            return typeof(TilesetReader).AssemblyQualifiedName;
        }

        protected override void Write(ContentWriter output, Tileset value)
        {
            output.Write(value.Tiles.Count);

            foreach (var item in value.Tiles)
            {
                WriteTile(output, item);
            }
        }

        private void WriteTile(ContentWriter output, Tile tile)
        {
            RuledTile ruledTile = tile as RuledTile;

            if (ruledTile != null)
            {
                output.Write(true);
                output.Write(ruledTile.Rules.Count);

                foreach (var item in ruledTile.Rules)
                {
                    output.WriteObject(item.Neighbors);
                    WriteTile(output, item.Tile);
                }
            }
            else output.Write(false);

            output.Write(tile.Sprite.Map);
            output.Write(tile.Sprite.Id);
            output.Write(tile.Color);
            output.Write((int)tile.SpriteEffect);
            output.Write((int)tile.ColliderType);

            if(tile.Animation != null)
            {
                output.Write(true);
                output.Write(tile.Animation.Duration);
                output.Write(tile.Animation.StartFrame);
                output.Write(tile.Animation.Sprites.Count);

                foreach (var item in tile.Animation.Sprites)
                {
                    output.Write(item.Map);
                    output.Write(item.Id);
                }
            }
            else output.Write(false);
        }

    }

I am using Monogame from Nuget package. Maybe you can somehow put a “break point” for debugging inside the ContentManager?

GetRuntimeType must return the type the object you are reading. not the reader.
In this case probably it’s typeof(Tileset).

You can add a System.Diagnostics.Debug.Break() anywhere in your code and that will fire up a new instance of VS. But this method is a bit frustrating.

The better method is to debug it from within the project.
Open the properties of the processor project and go to debugging.
Set external program to the mgcb.exe
Set working directory to the content directory
Add a command line argument to either /@:content.mgcb
or directly inline the processor parameters.

You need to adapt this example to MG3.8.1. because MGCB.exe has been renamed,
and you have to run it as a dotnet tool. I don’t know the details to that, but the idea is the same.
Once you hit debug(F5) it will break on the first breakpoint in your code.

Thank you very much! I will try.