sharepointsharepoint-2010sharepoint-2013event-receiversharepoint-feature

How to fix SPFeatureDefinition does not contain a definition for RootDirectory


I'm very new to SharePoint development, and I'm just trying to add an XML file to a Feature to reference the XML file content in the feature Event Receiver.

It seems that the general recommendation is to use do so like in this SO question:

How to retrieve data from an XML file in a Sharepoint 2010 Feature Event Receiver?

However, my code does not compile when I reference the RootDirectory property. The error I see is below

'Microsoft.SharePoint.Administration.SPFeatureDefinition' does not contain a definition for 'RootDirectory' and no extension method 'RootDirectory' accepting a first argument of type 'Microsoft.SharePoint.Administration.SPFeatureDefinition' could be found (are you missing a using directive or an assembly reference?

Now, the weird part is that while debugging, I am able to evaluate the RootDirectory property correctly in the Quick Debug window.

Am I missing something obvious? Like I said, I'm completely new to SharePoint.

My feature is scoped to the Web level, and I do have a reference to Microsoft.Sharepoint.Administration in my using statements.

Any help is greatly appreciated, thanks.


Solution

  • It was indeed something very basic.

    The solution/project was set as Sandboxed. Just going to the properties of the project (not the property pages but hitting F4 while the project is selected on Solution Explorer) and setting Sandboxed to false will let you compile when you're accessing the RootDirectory solution in code.

    Also, a few other properties/method not show up when the solution is Sandboxed instead of marked as a Farm solution.