Content.Load can't find texture

I just started trying out MonoGame, but when I try to launch the simple code I’ve made, it says it can’t locate the image I’m trying to use.

This is the code I have right now in the LoadContent() method, and I have my picture on the desktop in a folder called “Images” and the picture is called “ship.png”

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

                ship_texture = Content.Load<Texture2D>("Images/ship.png");
    }

Open your project
(In visual studio), look to the solution explorer, that is typically on the right of your project showing all files associated with your project, you will see a orange icon that is labeled Content.mgcb.

Double click to open the Content.mgcb tool (mentioned above).
(it should open the content pipeline tool window)

Select
Edit -> Add -> Existing item
(this will open a file browsing window)

Find your image in the browsing window and select it
(e.g. in your desktop or were ever. You may get a prompt to copy or add a reference link to the image)

Copy the item in if you are offered the option to do so. (this will place it within the content folder of your project and link it to be build or rebuilt as needed into a xnb in the projects bin folder)

Build or rebuild all the items in the tool and then click File -> Save

Close the tool.

In your project’s code, we change that line to.

ship_texture = Content.Load<Texture2D>("ship");

the content pipeline initially points to the current projects content folder or bin by default.

Build your project, it should compile without error, you can also edit the image and recompile it from visual studios build or rebuild command.

ContentManager can’t load images directly. They have to be processed by MonoGame’s Content Builder (MGCB) tool. @willmotil shows you how it’s done using the Pipeline Tool, MG’s graphical frontend to the MGCB tool. The Pipeline Tool will produce files with the .xnb extension. The .xnb files need to be in your project’s bin folder to be loaded by the ContentManager. See the docs page for information: http://www.monogame.net/documentation/?page=Using_The_Pipeline_Tool

And when you add it, omit ‘.xnb’ from the file name…

1 Like