The content file was not found

Hi, (I’m french so sorry for my bad english)

I tried to load a content (Content.Load Texture2D) but that say “The content file was not found.”. The file is in the content folder ! Please somebody can help me ? ^^’


The ContentManager works with .xnb files, so you’ll have to run your .png through the Content Pipeline.

If you want to load a raw Texture2D, use Texture2D.FromStream. Here’s an example of how to do so.

Thanks ! But I don’t have “RenderingManager”

You don’t need that whole class; only the snippet loading the Texture is relevant. Here’s a method:

public Texture2D LoadRawTexture(string filePath, GraphicsDevice graphicsDevice)
    using (FileStream fileStream = new FileStream(filepath, FileMode.Open))
        return Texture2D.FromStream(graphicsDevice, fileStream);

Important to note is you must dispose the Texture2D when you’re done with it after loading it in this manner.

That’s work ! Thank you so much

Hey it’s me again, do you know how to make it not null ?

You have to instantiate and initialize your GraphicsDevice. Your Game1 class in Game1.cs already does this, so you can use that one.

Also when you load raw assets, you will need to specify more of the path. For instance, instead of “MySprite.png,” you will need “Content/MySprite.png.” This all depends on how your project is structured.

1 Like

It’s works, I don’t have any error. But I have a Black Screen instead of the image, can you help me ? (Promised after I do not bother you anymore)

Are you drawing anything to the screen?