I have been using the method described here by attempting to use reflection to turn on the Rating Settings of a list. However, I get the following error:

Exception Message: exception has been thrown by the target of an invocation

Stacktrace Message: Value cannot be null.Parameter name: serviceContext

Here is my attempt:

//Create the list
Guid id = web.Lists.Add("Board Name", "Board Desc", SPListTemplateType.DiscussionBoard);

//Retrieve the list I just created
SPList discBoardList = web.Lists[id];

//Attempt to turn on the Rating Settings for the newly created list
Type type = typeof(Microsoft.SharePoint.Portal.RatingsSettingsPage);
MethodInfo mi = type.GetMethod("EnableRatings", BindingFlags.Static | BindingFlags.NonPublic);
mi.Invoke(null, new object[] { discBoardList, true }); //EXCEPTION THROWN

How do I resolve this issue? Or more importantly is there an easier/better way to turn on Rating Settings for a SharePoint list programmatically?


are you creating your list programmatically or it is generated using the OOTB options ?

if you are creating the list programmatically then you can use the below method to enable ratings in your list schema.

Add this to your default view (or any view you want) in Definition Schema of the List

          <FieldRef Name="AverageRating" />
          <FieldRef Name="RatingCount" />


Follow this link

You will have to create a content type containing the references of the ratings field and will have to add that content type in the list schema.

I am not very much sure about it but you can also try This Link as well and see if it solves your problem

  • Yes I am creating the list programmatically. Per your suggestion I tried: SPView view = discBoardList.DefaultView; view.ViewFields.Add("AverageRating"); view.ViewFields.Add("RatingCount"); view.Update(); But go the Item does not exist. It may have been deleted by another user exception thrown. Please advise. – KidBatman Jul 31 '15 at 16:17
  • Do you have any control over the XML defined schema of the list.? – Vishwas Goswami Aug 3 '15 at 4:44
  • No, unfortunately I don't. – KidBatman Aug 3 '15 at 16:32
  • have you seen the edit for the answer i made and checked both of the links in it ? – Vishwas Goswami Aug 4 '15 at 4:19
  • DId your issue got solved ? – Vishwas Goswami Aug 13 '15 at 6:27

As a workaround I just grab the default "Discussions List" that is created when creating a Community site. When I start adding the list items all numbers in What's Happening come out correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.