man thinking


What could be simpler? You write a trivial console application with the usual first line "using (var site = new SPSite(http://myurl/)) {". You are sure you got that URL right, and yet every time you try to run it - BZZZZZZT - you keep getting that pesky System.IO.FileNotFoundException. Yes, you are definitely running that on a SharePoint server. What on earth is going on?

The trouble is, Visual Studio always assumes you want to write an x86 application. For SharePoint applications you need to be x64. Go to your project settings and on the build tab next to "Platform target" choose x64 from the dropdown.

screenshot of error message

It seems so obvious, and yet I seem to somehow forget to set the target platform almost every time I write a "quick" lightweight application.

On a related note, if you are using SharePoint 2010 and you build against version 4.0 of the .NET framework (again, the default) you will get a System.PlatformNotSupportedException. For SharePoint 2010 projects you need to select version 3.5 under the Application tab, where it says "Target framework".