Error: The Web application at http://localhost/ could not be found

Ok, so I’ve run into the first (small) problem. As I was working on a small tool (which is supposed to solve another small problem I ran into), which retrieves all lists in a certain web, I immediately ran into a problem. Figures, problems with the first line of code. Good excuse to post some code and try this wp-plugin. As I am pretty new to this SharePoint coding, I am open for suggestions and tips and will adjust articles and code accordingly.

 C# |  copy code |? 
01
            using (SPSite site = new SPSite("http://localhost/"))
02
             {
03
                 using (SPWeb web = site.OpenWeb(""))
04
                 {
05
                     foreach (SPList l in web.GetListsOfType(SPBaseType.GenericList))
06
                     {
07
                         Guid myGuid = l.ID;
08
                         string strName = l.Title;
09
                     }
10
                 }
11
             }

I got the following error message:

The Web application at http://localhost/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

The solution was very simple, the target platform is x64 while a new project by default targets x86. So go to the menu Build -> Configuration Manager and change the active platform to x64.