SpriteBatch System.IO.FileLoadException

I just started learning MonoGame, I am teaching it from this lesson: leasson.
Here is the code where the error occurs:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using System;
using System.Collections.Generic;
using System.Text;

namespace rpg
{
 class MainGame : Game
 {
     private GraphicsDeviceManager manager;
     private Map map = new Map(32, 32, 10, 10);
     private SpriteBatch spriteBatch;

     public MainGame()
     {
         manager = new GraphicsDeviceManager(this);
         
         IsMouseVisible = true;
     }

     protected override void Draw(GameTime gameTime)
     {
         GraphicsDevice.Clear(Color.CornflowerBlue);

         map.draw(spriteBatch); // <-- Exception here

         base.Draw(gameTime);
     }

     protected override void Initialize()
     {
         spriteBatch = new SpriteBatch(GraphicsDevice);
     }
 }}

2021-10-28_222005

This map.draw method:

public void draw(SpriteBatch spriteBatch)
    {
        Vector2 tilePosition = Vector2.Zero;

        spriteBatch.Begin();

        for(int x = 0; x < width; x++)
        {
            for(int y = 0; y < height; y++)
            {
                spriteBatch.FillRectangle(tilePosition, new Size2(tileWidth, tileHeight), Color.Black);
            }
        }

        spriteBatch.End();
    }

I see you used monogame extended, or some such… Is this your first code, or is your installation of visual stufio, monogame, etc, confirmed working?

… Now I don’t know extended, and thus not the Map class, but does it need to load some content? You are drawing but not loading content, as far as I can see… Don’t know if that is intentional, depending on what Map does… But yeah. Are you supposed to be loading content somewhere, ie pictures?

Here is the whole map class:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended;

using System;
using System.Collections.Generic;
using System.Text;

namespace rpg
{
class Map
{
    private int tileWidth;
    private int tileHeight;
    private int width;
     private int height;

    public Map(int pTileWidth, int pTileHeight, int pWidth, int pHeight)
    {
        tileWidth = pTileWidth;
        tileHeight = pTileHeight;
        width = pWidth;
        height = pHeight;
    }

    public void draw(SpriteBatch spriteBatch)
    {
        Vector2 tilePosition = Vector2.Zero;

        spriteBatch.Begin();

        for(int x = 0; x < width; x++)
        {
            for(int y = 0; y < height; y++)
            {
                spriteBatch.FillRectangle(tilePosition, new Size2(tileWidth, tileHeight), Color.Black);
            }
        }

        spriteBatch.End();
    }
}

}

It should draw a black square, like this2021-10-28_222005

ok, can you set a break-point inside the map class draw method, to see if your execution reaches into it at all, or it crashes before that point?

Edit: Since your error-message reads: “…monogame…” are you sure you have monogame and extension working, ie have you run this project in an earlier state, or other previous project, to verify you have a good installation?

-Maybe some versions of libraries/add ons are out of sync with each other or something like that… I don’t use extended, so don’t know if you need to be worried about version compatability with regular monogame

… But I DID do little research, and found out you DON’T need to call LoadContent to do what you are doing… Your code matches the tutorial, it seems, so your problem might be in the setup of your editor / environment.

You can try to create a MonoGame project from a template as an easier starting point. If you’re using Visual Studio 2019, just follow these directions and see if the empty project compiles and runs for you.

https://docs.monogame.net/articles/getting_started/1_setting_up_your_development_environment_windows.html#install-monogame-extension-for-visual-studio-2019

https://docs.monogame.net/articles/getting_started/2_creating_a_new_project_vs.html