Friday, July 9, 2010

SP2010-Visual Studio 2010-Console Application:The Web application at could not be found. Verify that you have typed the URL correctly.

As any other application development process we use console application time and again to test piece of code. Now when developing in a Visual Studio 2010 and SharePoint 2010 environment, when using straight console application project and when trying to use :

SPSite site = new SPSite(http://dev/)

It throws an error:

"The Web application at 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."

We would developing normally thinking that VS 2010 Console Application project template would have taken care of everything, but unfortunately, the platform target for Console App is still X86 but in fact we are on SP 2010 server which is always going to be a 64 bit machine.

Solution:
  • Goto project properties of console app.
  • Click Builds tab
  • Change the Target Platform to "Any CPU"
  • And you should get your SPSite object instantiated successfully.