2
\$\begingroup\$

I've developed a while back in XNA but I'm a bit rusty. I've started working on SL XNA but have a problem I can't explain while trying to load content (model -fbx- or texture).

I place the image named redRect.jpg in the Content project by right-click -> Add existing item and I've made sure all the properties are ok:

  • Asset Name: redRect
  • Build Action: Compile
  • Content Importer: Texture - XNA Framework
  • Content Processor: Texture - XNA Framework

I declare a texture

Texture2D redTexture;

but when I try to load the texture

redTexture = contentManager.Load<Texture2D>("redRect");

I get an error telling me that the image is not found

Error loading "redRect". File not found.

\$\endgroup\$

3 Answers 3

2
\$\begingroup\$

You seem to have the content file properties right.

The next thing that comes to mind is that maybe your redRect.jpg is not in a root of your content project. This would be the issue. If you have the content file in a subdirectory of content project, lets say "textures", you need to specify path to the asset including that folder name like this:

redTexture = contentManager.Load<Texture2D>(@"textures\redRect");

If that is not the case and you have redRect.jpg in a root of your content project and still getting this error, try setting the root directory for your content manager explicitly like this, before loading the content:

contentManager.ContentRoot = "content";

Otherwise, if there is still an issue, verify that the content reference to the content project is properly set in your SL XNA project. This reference should be created automatically by Visual Studio when creating the SL XNA project.

\$\endgroup\$
1
\$\begingroup\$

This is probably a rather obscure answer, but my symptoms were exactly the same (throwing a ContentLoadException loading redRect) so I hope this helps anyone who is suffering the same unlucky fate.

Apparently there is a bug that means the path length can cause referencing problems (in this case my content project wasn't being found). By starting again with a different project name (a longer name!), everything worked fine. (I'm just doing the XNA tutorials so starting again is not a problem, I expect moving the solution directory would also fix this)

\$\endgroup\$
-1
\$\begingroup\$

Try

redTexture = Content.Load<Texture2D>("redRect");
\$\endgroup\$
1
  • 1
    \$\begingroup\$ This would be the same as OP is doing. The contentManager is the App.Content in the default SL XNA project: contentManager = (Application.Current as App).Content; \$\endgroup\$ Jan 11, 2012 at 16:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .