Lesson 02.2B – Fixing the namespace

If you use a different project name…

There’s one thing you need to do if you gave your UI project a name other than SuperAdventure, change the project’s namespace.

A namespace is a way to group your classes together.

When you create a project in Visual Studio, it will use the project’s name as the namespace name. So, if you name your project “MyAwesomeGame”, its namespace will be “MyAwesomeGame”. The problem you’ll have is if you copy/paste code from my code samples, it expects the namespace to be “SuperAdventure”.

Fortunately, there is a simple way to make the program work.

 

Open your solution in Visual Studio.

Right-click on your UI project name (in Solution Explorer) and select “Properties”.

Project properties menu in Solution Explorer

Click on “Application” (on the left-side menu).

Change the “Default namespace” value to “SuperAdventure”.

Project solution page, with default namespace textbox

 

Now you can copy and paste the code from the lessons, and not have problems due to the namespaces not matching.

2 thoughts on “Lesson 02.2B – Fixing the namespace

    1. The namespace is an artificial name, for us to group our classes in a way that makes sense to us. We only use it to say, “all these classes are in the XYZ namespace group.” In fact, if you create a folder in a project, and create classes underneath it, their namespace will be “ProjectName.FolderName”, instead of just “ProjectName”.

      The assembly name is the name of the file that is saved on disk.

      The assembly name is only used when Windows looks for the file to load into memory. Once the file is loaded and running, and the program is looking for the classes in memory, it will use the namespace. So, it is OK for them to be different.

      Let me know if that didn’t make sense.

Leave a Reply

Your email address will not be published. Required fields are marked *