I was writing a custom SharePoint feature the other day and probably killed a few hours on this error and still don’t have an answer to it just yet.
using (SPWeb web = (SPWeb)properties.Feature.Parent) //since SPWeb is unmanaged code
//check to see if our list exists already
//storageList = web.Lists[PAGE_VIEW_LIST_VALUE];
storageList = web.GetList(web.ServerRelativeUrl + "/Lists/MyCustomList");
catch (Exception ex)
storageList = null;
As you can see in the above code, I am merely trying to get a reference to my custom list using the SPWeb.GetList method. Everything I have read says that the GetList method is the most efficient means of getting a reference to a SPList object as opposed to SPWeb.Lists[“MyCustomList"]. The problem was that everytime this code ran, it would NOT get a reference to my list and would instead throw an error. I verified the URL countless times and tried everything, but still got an error whenever the feature was activated and this code ran. I then decided to write a quick win app with the same code and BAM!…it worked fine!
So…..I still don’t have an answer at the moment (when I get time, I’ll revist this) but for the time being I switched over to the SPWeb.Lists[“MyCustomList”].
To all the SharePoint dev’s out there writing custom features…look out for this error.