8

When trying to import an image into my 'game' I get a error message. The one displayed in the title. it is called content1.png and is in the Content folder. I have

public override void LoadContent()
{
    base.LoadContent();
    path = "Content/content1.png";
    splash1 = content.Load<Texture2D>(path);
}

and it doesn't load it.
I have no idea what to do here.

stepper
  • 1,147
  • 2
  • 14
  • 22

3 Answers3

15

It's seems like the content.Load<Texture2D> method tries to open the file from your File-System and it is not founded there, do the following to solve it:

In Visual Studio -> Right-Click on the content1.png file -> Select Properties ->

  • Set the Build-Action to "Content" in the properties window for content1.png.

  • Set the Copy to Output Directory to -> Always

Yair Nevet
  • 12,725
  • 14
  • 66
  • 108
  • Thank you, is there any way I can automatically put images to Always? Because I'm lazy. Doesn't matter if there isn't tough. – stepper Dec 24 '13 at 12:45
2

While the accepted solution didn't work for me, I finally figured out that it was the relative path of the asset that was creating problems, so changing

Content.Load<Texture2D>("Graphics\\MyAsset.png")

to

Content.Load<Texture2D>("..\\Graphics\\MyAsset.png")

did the trick for me.

dotNET
  • 33,414
  • 24
  • 162
  • 251
  • 3
    The latest monogame updates are driving me nuts... I have Monogame 3.5 on Xamarin, and now none of my content files want to load anymore. They did load on version 3.4. The properties of the file are set to 'content', but I still get the error "Could not load as a non-content file".... – Kokodoko Mar 21 '16 at 13:36
1

In MonoGame 3.5.1 you must use MonoGame pipeline tool for your resources, and include builded *.mgcb file to your content folder in project. See sample project Platformer2d.

MonoGame pipeline tool http://www.monogame.net/2016/03/17/monogame-3-5/

Samples https://github.com/MonoGame/MonoGame.Samples

Danil Shaykhutdinov
  • 2,027
  • 21
  • 26