Wednesday, 11 August 2010

Querying SharePoint 2010 SPSite from within console application results in FileNotFoundException

Tried to connect to a SharePoint 2010 sitecollection via a console application today, but it kept failing with an FileNotFoundException.

using(SPSite site = new SPSite("http://sps2010"){

Just for future reference:
  1. make sure your application is using the .NET 3.5 framework
  2. ensure it's compiled as 64 bit

As you'll have guessed by now: my app was using the visual studio 2010 default settings of .NET framework 4.0, compiled as x86 ... which obviously conflicts with the Microsoft.SharePoint assemblies (that are built on 3.5 and as 64bit.) :)


  1. Hi Tom, how do we ensure it's compiled as 64 bit?

  2. For others who run into this, i followed this from MSDN to convert to x64 for the project:

    In Solution Explorer, right-click the console application and click Properties. In the Project property page, select Application and set the target framework to .NET Framework 3.5, and then select Build and set the platform target to x64.

    I only had x86 available, so I clicked on the Configuration Manager button at the top right of the Properties window, and added the x64, selecting New and Copy from x86.