SharePoint 2010 Console Application Quirks

So, in order to get the schema XML of some field I’ve created on my SharePoint 2010 site, I decided to write a quick console application to retrieve the data.I quickly discovered that apparently some things have changed regarding how to use a console application with SP2010. I figured the code would pretty much be the same as it was in 2007:

const string siteUrl = "http://spfoundation/sites/testsite";

using (SPSite site = new SPSite(siteUrl))
   using (SPWeb web = site.OpenWeb())
      SPList list = web.Lists["Test"];
      SPField field = list.Fields["Languages"];


Running this code however, quickly resulted in an error:

The Web application at http://spfoundation/sites/testsite could not be found.

Surely I didn’t make a typo, as I copied the URL from the browser and it works over there. After some looking around for what to do, I figured out there are a couple of things you need to change:

  • You need to run Visual Studio 2010 as an administrator.*
  • The target framework of your application needs to be “.NET Framework 3.5″
  • Because SP2010 is a 64-bit application, the platform target of your application needs to be 64-bit as well. The setting “Any CPU” seems to be working as well.

(*) I installed SP2010 on a workstation running on Windows 7 Professional, so this requirement may be different for scenarios where your Visual Studio is running on a server with SP2010.

Be Sociable, Share!

One thought on “SharePoint 2010 Console Application Quirks

  1. Superb find. I googled and everywhere it was mentioned about the x64 bit and the target build framework but you spotted my issue about running VS on admin priviledges. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">