FileNotFoundException with the SPSite constructor

The FileNotFoundException is thrown by SharePoint when it cannot find the requested site collection in the SharePoint configuration database. My guess is that you have not yet created a site collection on the URL http://mysite:80. I see the following stack trace if I try and instantiate a new SPSite object with the URL of a non-existing site collection:

System.IO.FileNotFoundException : The site http://server/sites/bah could not be found in the Web application SPWebApplication 
Name=SharePoint - 80 Parent=SPWebService.
at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
at Microsoft.SharePoint.SPSite..ctor(String requestUrl)

Specify the proper URL of your site collection or open Central Administration and create a new Site Collection.


Changing the platform target in the build properties to x64 solved this issue for me on SharePoint 2010.