Vishal
Vishal

Reputation: 41

ContentLoadException problem

I'm very new to XNA. Actually I have XNA 4.0 book by kurt jaegers, so i installed VS 2010 and XNA 4.0 and wrote my first program. But that program didn't run successfully,it kept displaying the ContentLoadException file not found. So i did a bit of research on web and found that there is some issue with XNA 4.0. So I uninstalled the VS 2010 & XNA 4.0 and installed VS 2008(express edition) & XNA 3.0 . Then I compiled my first program on it and i ran successfully.

But,now I'm facing the same problem again with my new projects. I've tried both Syntax :

xx = this.Content.Load<Texture2D>("TitleScreen");
xx = Content.Load<Texture2D>(@"TitleScreen");

And there is no spelling mismatch problem. Please Mods guide me. And please tell me why I'm getting this problem again and again.

System Specs :
XP sp3,i3,2gb RAM.

Upvotes: 0

Views: 907

Answers (3)

user1459910
user1459910

Reputation:

There is a known issue with ContentManagers instanced by anything other than the default Game object constructor, which cause the problem you are experiencing.

If you are indeed using a ContentManager object other than the one supplied on the Game object, the solution is:

When you instantiate the ContentManager, you should set it's RootDirectory property to

@"Content"

Hope it helps

Upvotes: 0

lysergic-acid
lysergic-acid

Reputation: 20050

In order to properly load content, you'll need to use the generic method

ContentManager.Load<T>

For example, if you're trying to load a Texture2D element, Use the following syntax:

Texture2D texture = Content.Load<Texture2D>("textureName");

Read more about loading content in this link.

Upvotes: 0

user60456
user60456

Reputation:

Content that you want to load into via the ContentManager needs to be in the content project. Pretend for a moment it looks like this

Mygame.Content > SomeFolder > textureName

You would use content.Load<Texture2D>("SomeFolder/textureName") to get to it. If it was at the root of the Content project content.Load<Texture2D>("textureName") will work. If (and since) it isn't there are 2 things to check

  1. Right click on the texture and go to properties. Look at the AssetName properties. This is what you use to load it up via the Content Manger. Try using whatever this name is.
  2. The root directory the Content Manager looks in is "Content". Look at Content.RootDirectory and see what it is. If it isn't "Content" change it to that. That could also work.

Upvotes: 1

Related Questions