When ever I try to open a windows game 4.0 project it tell me "A problem was encountered creating the sub project 'windowsGame8'. Object reference not set to an instance of an object." Also for some reason There are two of every option in the xna new project folder in C#.
I dont' think those 2 errors are related. I can help you with object reference error.
If you are getting the "Object reference not set to an instance of an object" error your project is probably opened but not visible. To see it: check your Solution Editor, (View > Solution Editor) and choose the Game1.cs or the file you want to open.
About "Object reference not set to an instance of an object":
Check for the objects in your code. Before using them make sure they are created. If they are not created you will get this exception since a null object is trying to be accesed. Is like opening a door and finding a room with no floor, you will not enter there without a floor!
An example:
//Below Game1
Player player;
// in the LoadContent() method you have something like:
player.Initialize(texture, Vector2.Zero, texture.Height, texture.Width, blablabla);
// You NEED to create the player object, before using it in LoadContent(). To achieve this, inside Initialize() method you write:
player = new Player();
To actually understand the error, you need to know the basics of the Object oriented paradigm.
Thank you for responding to my question. I have had a lot of problems running code for C# forms that I have found on other forums. I have visual C# 2010 Express, but it seems like my version is different or something. I only mention because when I went into view it showed me start page, other windows, toolbars, fullpage. I went into other windows to find Solution Explorer, witch is different from what your example indicated I should see (Solution Editor). After looking in the explorer I found that I had no game files or any other than the reference file link. I downloaded my version from microsoft with the update thing. It's registered, and I'm stomped.
Oh I'm sorry that was an AWFUL error lol, yes, it is Solution Explorer.
Maybe the code you are copying from other websites is not using the same .Net Framework you have, (you probably have 4.0 or 4.5 if you downloaded the Editor recently. If you can take some screenshots or take a video to see the problems you are having, could help to see what is wrong.
Also google "A problem was encountered creating the sub project" and check the first 2 options, (in cache mode since the site is still down). Summarizing, what they say is that the files can be corrupted, try to reset Visual Studio Express or to reinstall everything.
I love seeing this kind of discussion here in the forums. For years, the forum has been a bit of a graveyard, but in the last few months, it's picked up quite a bit.
I don't know if ooplost solved your problem or not, but I just thought I'd throw in a few ideas as well.
If you're using Visual C# Express 2010, you're almost certainly using version 4.0 of the .NET Framework. Version 4.5 just barely came out, and 2010 doesn't support it. There's a 2012 version of Visual C# Express, but it can't handle XNA stuff yet, so that's not what you want. Ooplost has a good point, though. There's a lot of stuff about XNA on the Internet that is out of date, and if you're using something from XNA 2.0 or 3.0, it's not going to be compatible with XNA 4.0. So watch the version numbers of things.
The problems you're describing sound like a corrupt or misconfigured solution or project to me, though I tried to intentionally corrupt my solution/project files and I couldn't get the same errors you're describing. If so, I can think of a couple of fixes. One, you could open
up the .sln or .csproj/.contentproj in a text editor and double-check the paths that they list to make sure all of the files and folders listed exist.
Alternatively, if you don't have massive amounts of files, you could perhaps just start from scratch with a new solution and re-add all of the files. I've done that before, and it seems like you need to add each folder manually, and add the contents of each folder, one folder at a time. So it takes a little work, but if your game isn't massive, it's probably do-able.
As a final possibility, you can try posting the code you're working with online somewhere and sending us a link, or just emailing me your source code and I can probably check and see if the problem is happening for me as well. I've got about a million things on my plate at the moment, but it should be simple enough to check to at least see if I'm running into the same problem as you or not.
And finally, I want to quickly address what you're saying about two of every option in the New Project window. (I'm assuming you're talking about the window that comes up when you go to File > New Project.) If you're really seeing two of everything, something is wrong with your installation, and as ooplost suggested, it might be worth reinstalling everything.
BUT… I wonder if you're not actually seeing duplicates, just items that look similar, and mistaking them for duplicates.
What you //should be seeing is this:
- Windows Game (4.0)
- Windows Game Library (4.0)
- Xbox 360 Game (4.0)
- Xbox 360 Game Library (4.0)
- Content Pipeline Extension Library (4.0)
- Empty Content Project (4.0)
The first two have the same icon, the middle two have the same icon, and the last two have the same icon. Add on top of that a similar name, and I can easily imagine it being interpreted as double of everything.
If you're seeing something besides that, let us know what exactly you see listed there. (If you've got Visual C# selected on the left, you'll also see things like Windows Forms Application, WPF Application, etc.)
For what it's worth, there's very little difference between a Windows Game (4.0) and an Xbox 360 Game (4.0) project, and you can just pick one (probably the Windows one) and then do what they call "creating a copy of the project for the Xbox 360" later on.
The difference between the Windows Game and the Windows Game Library is that the library one doesn't have a main entry point, while the non-library one does. The library version is used to create supporting libraries where you can put code that is shared between multiple games. You never need a library project, but you can have them if you want. (Probably overkill for your first game.) Also, the library one will be compiled into a .DLL, while the non-library one will be compiled into a .EXE.
Anyway, my point with all of that is to give you some information about what you might be seeing. I know I'm basically spewing information at you that may or may not even be helpful in your situation, so if I'm just confusing you, just ignore my comments and continue merrily on your way. :)
Let us know if you get your problems fixed or if you're still having trouble with it!
WOW! Thanks for all the info. I am new, and I'm sure you know how overwhelming that can be in the coding world. I tried re installing everything, and found that the reason I was seeing two of everything was cause I double installed it before on accident when I was trouble shooting. So now only one of everything is there. I recently re-downloaded xna and C#, but what you said about the versions not matching up sounds like it could be a fix. Before I dig into that I will see if I just need to put the files in manually. Thank you I hope this works for me, if not I looks like I'll be starting from scratch.
I sure hope you don't need to recode everything from scratch. (Though, to be honest, the few times that I've lost everything for a project and had to rebuild from scratch, I was able to repeat what I had done before much quicker than the first time, and do it much better, so that it was easier to make changes going forward.)
You've got all of the files and resources, so you shouldn't need to do that. I think worst case scenario, you should be able to create a new project and then add the right folders to get the directory structure you had before and then just right-click in the right spot and choose Add > Existing Item… (or something like that) and import all of your old stuff. That's the worst case scenario, I think.
Let us know how it goes when you get done!

