Wednesday 21 July 2010

"Could not load file or assembly" - Solution

Today's task had just been completed...finally. I'm going to start talking compucrap for a while now so if your just interested in the RPG scroll down to the bottom of this post!

What should have taken an hour has taken me the best part of five hours. The aim of today was relatively simple: create the classes needed to work with XNA inside a windows form. "What the hell does that mean?" I hear you cry.

Well to avoid a lecture on what's what, for now just imagine that I'm trying to make a game run inside the "My Documents" browser. As you can imagine; this type of thing isn't meant to be done and requires a bit of work around to get these types of results. A game needs to be updated as quickly as possible (a minimum of 30 times every second to keep up with the human eye). A windows form sits there idly until it is moved or interacted with.

After an hour and a half I had written code that would enable me to have as many games as I wanted running in a single window. Upon testing the code all I saw was a window that showed a big red cross. It was like the computer had just looked me dead in the eyes and said that all to common word: "Denied!"

Obviously something was wrong, but what? I had hundreds of lines of code and the only hint of error the computer showed me was:

Could not load file or assembly 'Microsoft.Xna.Framework, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d' or one of its dependencies. The system cannot find the file specified

You what? What the hell does that mean? I sifted through the code for hours, thinking I must have made a mistake. But no, apparently I do know what I am doing, but my computer does not...

Here's the solution for all those directed to this page by google while trying to fix the same problem, because lord knows there's a lot of you!
If you are running a 64bit system, be sure to compile the program for a 32bit platform. By default visual studio selects the Debug folder and "Any CPU" as it's build preferences. You need to change "Any CPU" to "x86". This can be done by clicking:

Build -> Configuration Manager
Click the combo box under in the 'Platform' column
Choose
Under 'New Platform' choose 'x86'
Copy settings from AnyCPU

Well that didn't take long for the first tutorial...

As for the RPG:
As mentioned, I can now run multiple XNA games inside a windows form. This means that I can run a simulation of the game while the map is being created. No need to save the map, no need to compile anything. I can start walking around the map as soon as I place the very first object (preferably the ground, else I won't be walking far)

Better still, I have also implemented something that allows XNA to compile resources after the programs initial compilation. This means I can use any tile set at any time to create anything. This may not sound amazing, but if you know how XNA works with resources, I think you'll agree, that's pretty nifty! Next step is to start creating the code that will let me import tile sets and draw to the screen. I'm hoping for less trouble with that...

No comments:

Post a Comment