Maciek
Maciek

Reputation: 19893

XNA ContentLoadException

I'm starting to learn "some" XNA and - as expected - I've run into an obstacle pretty early.

/**/

protected override void LoadContent()
{
    // Create a new SpriteBatch, which can be used to draw textures.
    spriteBatch = new SpriteBatch(GraphicsDevice);

    logoTexture = Content.Load<Texture2D>("Sprites/MyImage1");

    // TODO: use this.Content to load your game content here    
}

I'm getting a ContentLoadException saying "not found" when trying to load one my *.png's

I'm pretty sure I'm making a common n00b'ish mistake, but I'm failing to see it, so I'd apreciate some guidance.

Problem Fixed

Content.RootDirectory = "Content"; // The cause of the problem

Regards

Upvotes: 2

Views: 4175

Answers (2)

Lukasz Madon
Lukasz Madon

Reputation: 14994

Why did you remove the content project?

My guess is that you need to set the RootDirectory

        Content.RootDirectory = "Content";

which BTW creates ContentManager object.

Upvotes: 3

Peter Lillevold
Peter Lillevold

Reputation: 33910

You should try the following path formatting instead:

".\\Sprites\\MyImage1"

According to MSDN, the path must be relative to the current directory. And the directory separator is '\'.

Upvotes: 0

Related Questions