Error occurred in deployment step Activate Features: This functionality is unavailable for field collections not associated with a list.

Thu, Aug 30, 2012 One-minute read

This follows on from some of my other posts about deploying fields and content types programmatically. In this case, I was simply trying to add a choice field (SPFieldChoice) to a site, and then add it to some content types.

So I had something like:

var myCt = // snip - code to get my existing content type;

// create the choice column
                var fieldChoices = new StringCollection() { "choice1", "choice2", "choice3" };
                var docSourceField = web.Fields.Add("MyChoiceColumn", SPFieldType.Choice, false, false, fieldChoices);

                // get the column we just created 
                SPFieldChoice docSourceChoiceField = (SPFieldChoice)web.Fields[DocumentSourceColumnName];

                if (null == docSourceChoiceField)
                {
                    throw new Exception("Error: Couldn't get the docSourceChoiceField.");
                }
                                // add the new field to my content type
                myCt.Fields.Add(docSourceChoiceField);
                myCt.Update(true);

However, running this fell over with the error:

Error occurred in deployment step ‘Activate Features’: This functionality is unavailable for field collections not associated with a list.

I naturally assumed this was due to an issue with creating the field. It actually wasn’t though - it was adding the new column to my content type.

The code to add the column to the content type is actually:

SPFieldLink fldLink = new SPFieldLink(docSourceChoiceField);
myCt.FieldLinks.Add(fldLink);
myCt.Update();

This will add your site column to your content type.