CSOM ServerVersion for the SharePoint 2013 November/December 2014 CU

In a recent experience I’ve found out that both the November and December 2014 CU for an on-premise environment are returning the same ServerVersion when requested via CSOM: 15.0.4675.1000.
For both CU’s the correct version is reflected in Central Admin:
– November CU: 15.0.4667.1000
– December CU: 15.0.4675.1000
See Steve Chen’s blog for a full list of all SharePoint 2013 version numbers.

If you have specific requirements in CSOM which depend on the December CU to be installed, you might want to check the ServerVersion property of the “ClientContext” object before you make the call but due to the fact it will return the November CU number for both the November/December CU this can result in unexpected exceptions. Known exceptions which will occur are:
– Using the SecondaryOwner property on the “Site” object;
– Updating the LocaleId property on the “RegionalSettings” object.

The below method provides a work-around for this issue and will return the correct ServerVersion. I know it’s not the best solution to test on an exception message, but it’s the only available work-around so far that solved my issue.

/// <summary>
/// Gets the correct SharePoint version number with the difference between the
/// November and December 2014 CU (OOTB both return the same version number)
/// </summary>
/// <param name="siteUrl">The URL of the site collection</param>
/// <returns>The SharePoint version number</returns>
public Version GetSharePointVersion(string siteUrl)
{
    Version novemberCU = new Version("15.0.4667.1000");
    Version decemberCU = new Version("15.0.4675.1000");

    using (ClientContext context = new ClientContext(siteUrl))
    {
        context.ExecuteQuery(); // Required to initiate the ServerVersion object
        Version sharePointVersion = context.ServerVersion;

        // Additional check needed for November/December CU
        if (sharePointVersion == novemberCU)
        {
            // The SecondaryContact property is only available in December CU
            context.Load(context.Site.SecondaryContact);
            try
            {
                context.ExecuteQuery();
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower().Contains("field or property") && ex.Message.ToLower().Contains("does not exist"))
                {
                    // Property doesn't exist, this is the November CU
                    return novemberCU;
                }
            }
            // Property exists, this is the December CU
            return decemberCU;
        }
        else
        {
            // Return the original version (it's neither the November/December CU)
            return sharePointVersion;
        }
    }
}