Partager via


The web application could not be found

Supposed you're using the following:
 - SharePoint Server 2010 or SharePoint Foundation 2010
 - Visual Studio 2010
 - .NET Framework 4.0

And you're trying to instantiate an SPSite object for a specific site collection, using the SPSite constructor as follows:

 SPSite mySite = new SPSite("https://testserver");

Now, although you're 100% sure that the URL to the site collection is correct, and that everything is OK from all perspectives (authentication, authorization, etc.), you still get the following exception:

System.IO.FileNotFoundException
The web application at https://testserver 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.

Puzzling, isn't it?
The solution is to open up your project's properties, select the Build tab and set the Platform target to either x64 or Any CPU. And that should do the trick!