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):