SPWebService.ContentService returning System.NullReferenceException

Home | SharePoint Development | SPWebService.ContentService returning System.NullReferenceException

When I tried to access SPWebService.ContentService in the following code-snippet (executed inside a console application), I was getting Null value.

 SPWebService contentService = SPWebService.ContentService;
            contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;

            SPWcfServiceSettings csomWcfSettings = new SPWcfServiceSettings();
            csomWcfSettings.MaxReceivedMessageSize = 104857600; // 100MB
            contentService.WcfServiceSettings["client.svc"] = csomWcfSettings;
            contentService.Update();

 

The resolution is to change the target CPU type in the Build properties from X86 to X64 or AnyCPu Type. That fixed my issue.

One thought on “SPWebService.ContentService returning System.NullReferenceException

Leave a Reply