Error occurred in deployment step ‘Activate Features’: Key cannot be null

While doing my project on SharePoint I came across this error while deploying the feature I have created.

Error occurred in deployment step ‘Activate Features’: Key cannot be null

Background

The error specifies that “Key cannot be null“. It simply means that one of the other XML field is empty or null. Before I have added content type everything was fine. Once I have added content type and was trying to deploy the same and got stuck with this. Then I checked my content type’s XML very closely and realize the problem.

Problem

<FieldRef ID="{A2035C99-1C42-4B1F-B402-08585B704333}" Name="lastName" DisplayName="lastName"></FieldRef>

Resolution

<FieldRef ID="{A2035C99-1C42-4B1F-B402-08585B704333}" Name="lastName" DisplayName="lastName"/>

When we create the content type in Visual Studio, it creates the empty <FieldRef> element which we change or we specify the value for few attributes (Here its ID, Name, DisplayName). But while deploying SharePoint does not understand this <FieldRef></FieldRef> empty element but it does understand the <FieldRef /> element.

Conclusion

Practice makes man perfect, I am also doing the same :-).

Posted in Sharepoint Tagged with: ,