A frequent problem found after distributing an XNA Game Studio game to another computer is double clicking the EXE only to get a window with this sort of message in it:
"<MyGame> has had an error and needed to close. Send an error report."
This message really could mean a couple of things:
- You didn't actually run the redists described in the dependency FAQ: http://forums.xna.com/thread/9924.aspx. First thing you should do is run all of those redists. Don't assume they are installed; run the redists and they will install if needed.
- There is an uncaught exception in your code.
To find out if there is an uncaught exception, follow these steps:
- First, add a reference to System.Windows.Forms in your game project.
- Next, in your Main method (found in Program.cs by default), wrap the entire code in a try/catch block that looks like this:
public static void Main()
{
try
{
using (Game1 game = new Game1())
game.Run();
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.ToString());
}
}
Run your game again. You should see a window pop up with the exception details printed. Now you can use this information to fix the uncaught exceptions in your game. For more information on exceptions and try/catch blocks, see these sites:
http://www.csharp-station.com/Tutorials/Lesson15.aspx
http://msdn2.microsoft.com/en-us/library/0yd65esw.aspx
http://msdn2.microsoft.com/en-us/library/dszsf989(VS.71).aspxhttp://msdn2.microsoft.com/en-us/library/system.exception.aspxIf, however, you run that code and don't see a window pop up with that information, that indicates you did not actually perform step 1 of installing the dependencies. Please use the link above to install the dependencies and run the game again.
Nick Gravelyn -- Microsoft XNA MVP
XNA Wiki |
Zune Games