SPSite - SharePoint 2010 and Visual Studio 2010 - FileNotFoundException

Trying to connect to my local SharePoint 2010 site using Visual abortion clinics Studio 2010 Asp.Net on Local IIS Web server Version 7.5 (Windows 7 x64) e.g.
SPSite oSpSite = new SPSite("http://LocalPCName:81");

I got the following error (FileNotFoundException):-
The Web application at http://LocalPCName:81 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 ru486 cost new request URL mapping to the intended application.


To Fix:-
Check what account the App Pool for "SharePoint Central Administration V4" is running under.  I use a generic account say Domain\SharePointAdmin.

Make sure this account is under the "WSS_ADMIN_WPG" local accounts group.

Make sure this account is site administrator for the site you are trying to connect to.

"Use Local IIS web server" rather than "Use Visual Studio Development Server" for Visual Studio Project Web debugging.  e.g. in Visual Studio for your project select Project - XXX Properties... - select Web (left tab) - tick "Use Local IIS Web server" - then click "Create Virtual Directory". 
Once created open Internet Information Services (IIS) Manager and find the newly created Web Application.  Select the web application and click "Advanced Settings...".  Change the Application Pool to the same one as the "SharePoint Central Administration v4".

The following I have seen people blog about that fixes their issues, but this was not necessary for me:-
Make sure the App Pool account has DB_Owner access to the SharePoint Configuration Database and the SharePoint Content Database.

Make sure your code runs under Platform Target: x64 (although I find Any CPU works better) - just make sure it is not x86 because SharePoint 2010 was only x64 bit hence it would not work.

Comments are closed