new SPSite – FileNotFoundException

It seems to me that every SharePoint developer, at some point in their career, will encounter this particular error. It’s one of those infuriatingly obtuse errors that could be caused by a multitude of different issues – either individually or cumulatively. In my case, I was in the middle of developing a SharePoint timer job and I had a particular piece of code that I wasn’t too sure about, and so wanted to test very quickly, over and over again – without the rigmarole of deploying/retracting solutions, hunting through Central Admin to run the job, etc. I just wanted to run this particular section of code against the SharePoint object model and see what happened. As is a common technique for this, I started up a fresh Console Application project, pasted in my code and figured that would be enough.

I was quite wrong and have spent the best part of the last 3 hours just trying to get the console app working. Since it was a standard C# console application, I added a reference to Microsoft.Sharepoint (14.0) and a using statement for the same assembly. The start of my code was the generic way just to get “in” to my SharePoint instance:

using (SPSite siteCollection = new SPSite(“http://sharepoint/”)) {

but when I then started debugging, it fell over on that line, with the “FileNotFoundException”. The web application and a site collection at that address definitely existed. Deploying a SharePoint solution in the usual way, worked. Running as the identity of the application pool, worked. So the key problem was in my own “Dev” account that I use to log in to the Dev machine.

So, it was off to Google for some advice. I won’t rehash everything I went through to get it working, but if you’re suffering from a similar issue, then you could start looking in any of these areas.

  • Is your devenv running as Administrator?
  • Does the process that your devenv/vshosts are running under have sufficient privilege to the Sharepoint farm? (Consider Site Collection admin, and possibly Farm Admin)
  • Does the user account have required privileges to the actual databases on the SQL Server?
  • Minimum of read/write on all content databases (common practice to give db_owner)
  • Read/write/db_owner main Config database and Administration Content database
  • WSS_CONTENT_APPLICATION_POOLS role on Config and Admin databases
  • Is your code compiled in 32-bit mode when you’re running on a 64-bit machine?

As it stands, I can’t be certain which of these “solutions” fixed the problem due to the fact that I tried them in various orders and did or didn’t restart various services/devenv/etc. throughout. But a combination of the above sorted me out – hopefully it can help you too. If there are any other common causes/solutions to this issue, feel free to leave them in the comments.

Some helpful links (check especially the comments in some of these):



Tags: , , , , , , ,

12 Responses to “new SPSite – FileNotFoundException”

  1. [...] you’ve encountered anything like this problem, then you may have had to update the permissions that a specific SQL login has. However, if [...]

  2. taqiyuddin says:

    hey man, thanks for the post. It helped me at “Is your code compiled in 32-bit mode when you’re running on a 64-bit machine?”

  3. [...] in order to resolve which route to take. The standard contingencies are explained quite well on http://www.thorntontechnical.com/tech/sharepoint/new-spsite-filenotfoundexception. None of those, possibly valid error causes, solved my beef.In the end I found that we don’t [...]

  4. Daniel says:

    Youy are genius ..

    converted a new build laptop to develop code for sharePoint server without a local instance of sharePoint .

    Then I wanted to quickly knock up a console app to spin though my webs …
    I sat there getting increasingly frustrated as to why I was getting a IOFileNotfoundException..

    then I switched the target platform to 64 bit and whey hey no exceptions.

  5. Marc says:

    Thankyou!

    tearing my hair out on this one – went straight to the last item in your list (» Is your code compiled in 32-bit mode when you’re running on a 64-bit machine?
    ) and then it worked !

  6. GW says:

    Also you need to ensure you target .NET 3.5 as it won’t work with .NET 4

  7. GW says:

    And I don’t think running Visual Studio as administrator makes any difference

  8. Tomek says:

    Thx, this “Does the process that your devenv/vshosts are running under have sufficient privilege to the Sharepoint farm? (Consider Site Collection admin, and possibly Farm Admin)” saved me :)

  9. Anuj says:

    Awesome man!! you saved my day..

  10. Amit says:

    Thanks, it helped

  11. Azam says:

    Unfortunately, I’m not as lucky as the other commenters. :-(

  12. Dustin says:

    This solved my issue: “Is your code compiled in 32-bit mode when you’re running on a 64-bit machine?”

Leave a Reply