While writing my first console application to communicate with SharePoint 2010, I was surprised to receive a FileNotFoundException during the creation of a new SPSite.

The line

SPWeb web = new SPSite(“http://localhost/”).OpenWeb();

returned the error statement:

FileNotFoundException was unhandled:
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.

FileNotFoundException

At first I assumed that the error was caused by invalid user rights, but after some searching this forum post at Microsoft Technet came up with the right solution.

By default the console project is build for the .Net 4 framework and and the x86 platform. Because SharePoint is only available as a 64bit version, the console app should also be compiled for the 64bit platform.

Update_Platform_To_x64_FileNotFoundException

By changing the framework to .Net 3.5 and the target platform to x64 the issue was resolved.