This project is read-only.

File Not Found

Jul 5, 2012 at 4:29 PM

I'm trying to make use of your dll, but I've run into an issue I can't seem to solve.  I'm making a game for the Microsoft Surface Table, and I've converted the game project so it works with your dll.  I've setup a new project, mimicking much of your sample project.  However, whenever I try to run the code, none of my texture files in my game will load. I keep getting a "File Not Found" error.  And when I look at the path it's trying to access, the files are there.  I can delete them and watch them repopulate when I build the project.  I've tried multiple approaches to try and correct this problem, but I've been unable to solve it.  Do you have any ideas?

Jul 5, 2012 at 10:45 PM

Hey Coryander,


     It seems like it might be defaulting to the wrong RootDirectory for the content. The sample - I believe - uses

RootDirectory = "Data"

because that's how the sample is set up. You might need to use a different RootDirectory to make sure your stuff is found. Try making sure to explicitly set your RootDirectory in the constructor of the Game, and also make sure to go to any ContentProjects you have for your game, going to its Properties, and setting up the "Root Directory" property in that Window to be the same as whatever you set it to in the Game Constructor.

Jul 5, 2012 at 10:55 PM

Thanks for the reply.

I made sure everything matched.  That was one of the first things I did.  I only copied the format of yours (I kept all the details and file names unique to my code).  My RootDirectory is set to "Content", and I set it in the game constructor.   Also the Content Root Directory property of my Content Project is also set to "Content" (sans the quotes).  I still have the problem.    

Jul 5, 2012 at 10:59 PM

What are the exact file names? When the Content Loader loads files, it expects you to omit the original extension. Everything should be showing up as XNB files when they're created and copied over.

I'm sorry if I'm saying things that sound basic or redundant, I just want to make sure I'm covering all the regular bases. The ContentManager for Xnaml is 0% different from the XNA one - in fact, it uses -exactly- the same ContentManager, so if file's aren't being found I can only think of regular errors that the ContentManager typically has when you call Content.Load<> on certain assets.

Jul 6, 2012 at 3:17 PM

I appreciate the help.  Yeah, I'm well versed in XNA, but this is my first time trying to use it in WPF.  I originally built the game and had it running on the Surface table, and now I'm trying to get it to work in a WPF window.  

Here's all the textures in my game (they are all pngs):

TextureLibrary.playerOneTexture = this.Content.Load<Texture2D>("Textures\\Paddle1");           

TextureLibrary.playerTwoTexture = this.Content.Load<Texture2D>("Textures\\Paddle2");           

TextureLibrary.puckTexture = this.Content.Load<Texture2D>("Textures\\Puck");           

TextureLibrary.leftGoalTexture = this.Content.Load<Texture2D>("Textures\\leftGoal");           

TextureLibrary.rightGoalTexture = this.Content.Load<Texture2D>("Textures\\rightGoal");           

TextureLibrary.gameBackground = this.Content.Load<Texture2D>("Textures\\Background");           

TextureLibrary.scoreTexture = this.Content.Load<Texture2D>("Textures\\Score");           

TextureLibrary.winnerTextureOne = this.Content.Load<Texture2D>("Textures\\winnerOne");           

TextureLibrary.winnerTextureTwo = this.Content.Load<Texture2D>("Textures\\winnerTwo");


And in the Content Project, I have all the textures in a folder labeled 'Textures'.  When I build the project, I can watch the xnb files populate in the bin\x86\Debug\Content\Textures directory; however, the code keeps giving me the "File not found" error.

Jul 6, 2012 at 8:00 PM

Well, everything -looks- right, and when I do the same thing with different file assets and new projects it all lines up to me.


Since it says FileNotFound Exception, so I'm just going to fully assume it's looking in a place that it can't find the file.

What I will say is that there is the potential for the directory to be in the inherently wrong directory: if your game file is set up as a separate project/DLL/.EXE from the WPF one (and it's just being loaded in as a separate project, which is what I do in the Sample), then it could be tracking the root based on the WPF application's path rather than the game DLL/EXE's path, or even Vice Versa:

A sample directory tree (based on debug or some such, no idea how accurate this is for you or how the structure works for Surface applications)

[ Debug ] 
> WPFApp.exe
> [ Content ]
> [ SurfaceGame ]
> > SweetGame.dll (or .exe)

In this case, it might be looking in [ Debug/SurfaceGame/Content ] for your folder (if that's how it's set up) rather than in [ Debug/Content ]. What you'll want to do to make sure the RootDirectory is finding it's file is that - using the StepThrough Debugger, Immediate Window, or just some quick test variables in your LoadContent method or something - just look at the results of these:

Path.GetFullPath( "Content\\Textures\\winnerTwo.xnb" );
Path.GetFullPath( Path.Combine( Content.RootDirectory, "Textures\\winnerTwo.xnb") );

See what string those spit out, and the full path may tell you if it's finding the right stuff or in the right directory.

Lemme know how it all goes. 

Jul 6, 2012 at 8:30 PM

It was looking in the debug directory of the WPF app rather than that of the XNA game.  As a quick workaround, I copied the xnb Content directory into the WPF app's debug directory, and the code launches.  I am no longer getting the File Not Found error.  Thanks again for the help.

Jul 6, 2012 at 9:02 PM

A permanent fix would be to tell the Project to copy over all its output files from the XNA Game Project into the WPF application. Usually this happens automatically when you tell the WPF Application that is has a dependency on the XNA game, and happens even moreso when you go to the Properties of your XNA game and set it to be a

Class Library

rather than an Executable File. Whenever the Game's DLL is linked with the Application and you build, it should copy not only the SurfaceGame.DLL into the same folder as the .EXE, but should take the Content folder and any other relevant things with it.

Have fun!