Friday, December 31, 2010

FileNotFound Exception while creating SPSite Object

The file not found exception could be one of the first SP 2010 exception any developer could face. For one it is surely something we did not encounter in 2007.

The usual suspects are well documented in many blogs:
http://edwin.vriethoff.net/2010/03/22/visual-studio-and-sharepoint-2010-new-spweb-returns-filenotfoundexception/

they are related to
1. project not compiled against .net 3.5
2. platform target not x64 or any

another 1 to look for is debug platform target is not x64. Check this in Project --> Properties --> Debug tab
If you have trouble setting this use the configuration manager, you can invoke the dialog from the debug drop down you see in tool bar.

I am not elaborating these much because that is not the point of this blog, I could find the above three solutions well documented else where

If your simple new SPSite (url) does not still work (mine dint) then start fiddling around for some clues at the usual places - eventvwr logs, 14 hive logs etc.,
what I found in eventvwr application logs is this


SQL database login for 'SharePoint_Config' on instance 'axxxxxxx' failed. Additional error information from SQL Server is included below.


Login failed for user 'xxxx\yyyyyy'.


That's it, this very informative error message can be thrown even if the user account under whose content ur code is running (logged in user if it is a console app) does not have login rights - and probably read access as well..
Go ahead and provide the necessary permissions - if u had broken ur head for 3 hrs to get around to this point, you would most likely end up giving sysadmin priv to the user and get past this error like i did, but pbly read on config and the content db shd be enough.

No comments: