SPSite Constructor Yields FileNotFoundException

It seems that I get sucked back into SharePoint bi-annually or so.  This time around it’s 2010.  The most basic app I can think of is a not-quite Hello World app talking to SharePoint.  It’s so simple that it’s a even a one-line console app:

Console.WriteLine((new SPSite("https://sps2010")).RootWeb.Title);

It failed.

From the title of this post, I’m sure you know that the error I got was “FileNotFoundException.”  Apparently, there are a LOT of reasons this can happen, and it’s almost as dreaded as the ubiquitous COMException.

A little Bing-ing around gave me a clue to the solution.  Well, let me be clear, this is the solution in MY case, as I said before, there are several causes for this issue. 

I failed to change the executable to be 64-bit (or Any CPU):

SharePointFlub01

SharePoint 2010 is a 64-bit server application, and it just doesn’t play well with x86 (32-bit) executables.  Visual Studio defaults console apps to be x86, but it defaults SharePoint Projects to Any CPU, so there are no problems there.  So after switching my “Platform target” to Any CPU my error went away.