Can’t create SPSite object in SharePoint 2010: FileNotFoundException: 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.

I wrote my first console app against SP2010 in VS2010 the other day and ran into the above exception at the very first line:

using (SPSite site = new SPSite(http://localhost)

It turns out because my console app was targeting x86 and SP2010 is of course x64. Changing the console app to x64 (or Any CPU) in Project Properties \ Build solved the problem.

Advertisements

About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.
This entry was posted in SharePoint. Bookmark the permalink.

2 Responses to Can’t create SPSite object in SharePoint 2010: FileNotFoundException: 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.

  1. Huy says:

    Hi Bernado,
    I met that problem when I created an console app with SharePoint 2010 in VS2010. So I’m still getting that problem althought I change the platform to x64 (or Any CPU), change the target framework to 3.5 instead of 4.0, and run my app as Administrator. When I used stack trace, I got an exception “Login failed for user “domain\user” (my account) ” (Sql exception). Can you help me solve this problem? Thank you.

    • Bernado says:

      Hey Huy,

      You mentioned “Login failed” and “Sql exception”, so it sounds like your problem is security/permission related – and is not the same exception/issue that I described in this post. You mentioned that you ran the app as Administrator – so I’d first check that you can browse to the site OK using IE under the Administrator account. At what line of code are you getting this exception?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s