Search code examples
c#xnaxna-4.0

XNA ContentLoadException


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

  • I've created a WP7 XNA Game solution
  • I've removed the default content project
  • I've added my own content project "Sprites"
  • I've added 3x *.png files to the "Sprites" project (MyImage1.png, MyImage2.png, MyImage3.png)
  • I've added a Content reference, referencing the "Sprites" to the main game project

/**/

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 did check the output directory, a "Sprites" subfolder containing *.xnb files is present
  • I did check the properties of the images, all are marked as Texture2Ds and have content importers and processors set to default XNA values

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


Solution

  • 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.