Visual Studio and SharePoint 2010 new SPSite returns FileNotFoundException

March 22, 2010   13:26


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.

Tags: , , , , , , , , , .





17 Comments »

  1. This problem also occurs when you try to communicate with the farm; SPFarm.Local will be null when the platform target isn’t x64.

    Also, when using MSBuild and AnyCPU made build tasks against SharePoint x64 (2007+) make really sure that you use the x64 version of MSBuild in the Framework64 folder else you’ll encounter some of the same problems (Visual Studio command prompt uses the x32 version by default, even on a x64 platform which i didn’t notice until i logged the contents of the $MSBuildBinPath property to the screen…)

    Comment by Cyriel — March 25, 2010 @ 8:07 am

  2. @Cyriel, thanks for sharing the additional information!

    Comment by Edwin Vriethoff — March 25, 2010 @ 3:08 pm

  3. Was googling around, until I ran into this post. That’s the exact information I needed!

    Thanks for posting :)

    Comment by NoBody — July 16, 2010 @ 2:24 pm

  4. Thanks, solved my problem, saved me some time.

    Comment by Zarko — December 10, 2010 @ 11:39 am

  5. This error can also happen if the in user does not have permission to login to config db.. I ran in to this and have doc’ed it here:
    http://buddhian.blogspot.com/2010/12/filenotfound-exception-while-creating.html

    Comment by Buddhian — December 31, 2010 @ 10:42 pm

  6. I am getting same error from my ASP.NET application. What all changes I have to do, to resolve it.

    Comment by Srinu — February 8, 2011 @ 12:00 pm

  7. Muchas gracias, soluciono mi problema.

    Saludos

    Comment by Rodrigo — February 9, 2011 @ 5:04 pm

  8. Very useful… I stuggled around 2 hours and this helped me….

    Comment by Ram — July 20, 2011 @ 10:20 pm

  9. i already try change to 64x n .Net 3.5 Framework, but when i run the web project its fail

    Comment by leonita — August 10, 2011 @ 9:29 am

  10. i use visual std.2010, and SP 2010

    Comment by leonita — August 10, 2011 @ 9:30 am

  11. Thanks. This article will solve my problem after a long time. Agian a big thanks to you.

    Comment by Rohit Kesharwani — September 23, 2011 @ 12:42 pm

  12. You rock!

    Comment by Ahmed IG — September 25, 2011 @ 1:47 pm

  13. The Web application at http://devsrv.com 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.

    Comment by I use a WCF and open a site . It throw error the same — November 4, 2011 @ 10:19 am

  14. true religion jeans outlet where you can buy discount true religion jeans online with worldwide free shipping

    Comment by discount true religion jeans — November 16, 2011 @ 10:58 am

  15. Thanks buddy.. :)

    You really saved so much time ..

    Comment by Manish Nath Choudhary — December 19, 2011 @ 10:10 pm

  16. [...] Edwin Vriethoff » Visual Studio and SharePoint 2010 new SPSite …Mar 22, 2010 … While writing my first console application to communicate with SharePoint 2010, I was surprised to receive a FileNotFoundException during the … [...]

    Pingback by Filenotfoundexception sharepoint | Shelbywayne — December 30, 2011 @ 6:35 am

  17. Thanks a ton buddy!!! It works like charm. :-)

    Comment by Sanket Sirotiya — January 6, 2012 @ 7:19 am

RSS feed for comments on this post. TrackBack URL

Leave a comment





The content expressed in this blog are those of Edwin Vriethoff and do not represent his employer's view in anyway. The contents of this blog has been carefully put together, but Edwin Vriethoff is not responsible in any way for any direct or indirect harm caused by individuals or organizations using the content of this blog in any way.