none
Programmaticly follow a site for a specific user is not working anymore after installing October 2015 CU RRS feed

  • Question

  • We wrote a simple C# webservice to let people automatically follow specific sites.

    This code was working for us in the past without any errors. But since we installed the current October 2015 CU this code stopped working. If we try now the set a site follow for a specific user then we get the following error:

    The operation failed because an internal error occurred. Internal type name:
    Microsoft.Office.Server.UserProfiles.FollowedContentException. Internal error code: 11

    We also tried to first get the SPUserToken from the specific user and opened a new SPSite-Object with this user token but this also ends with the same error.

    The Code always stops at Line: followingManager.Follow(actor);

    Any ideas how we could fix this?

    Code:

    SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    HttpContext savedContext = null;
    
                    try
                    {
                        using (SPSite site = new SPSite(siteurl))
                        {
                            SPServiceContext context = SPServiceContext.GetContext(site);
                            savedContext = HttpContext.Current;
                            HttpContext.Current = null;
    
                            if (context != null)
                            {
                                UserProfileManager profileManager = new UserProfileManager(context);
    
                                if (profileManager.UserExists(username))
                                {
                                    UserProfile userProfile = profileManager.GetUserProfile(username);
                                    SPSocialFeedManager feedManager = new SPSocialFeedManager(userProfile, context);
                                    SPSocialFollowingManager followingManager = new SPSocialFollowingManager(userProfile, context);
                                    SPSocialActor[] followers = followingManager.GetFollowed(SPSocialActorTypes.Sites);
                                    SPSocialActor foundActor = null;
                                    try
                                    {
                                        foundActor = followers.First(f => f.ContentUri.ToString() == followurl);
    
                                    }
                                    catch (Exception)
                                    {
    
                                    }
                                    if (foundActor == null)
                                    {
                                        SPSocialActorInfo actor = new SPSocialActorInfo();
                                        actor.ActorType = SPSocialActorType.Site;
                                        actor.ContentUri = new Uri(followurl);
                                        followingManager.Follow(actor);
                                    }
                                }
    
                            }
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    finally
                    {
                        HttpContext.Current = savedContext;
                    }
                });


    Regards, Simon


    • Edited by Simon-MCP Wednesday, October 28, 2015 10:27 AM
    Wednesday, October 28, 2015 10:26 AM

Answers

  • For a few days we got an answer from the Microsoft Support.

    They confirmed that this bug has been introduced with the September / October 2015 CU.

    This Bug should be fixed in the February 2016 CU.

    I will post another update as soon as we have installed this CU-Package.


    Regards, Simon

    FYI: Today we installed the SharePoint February 2016 CU in our farm. (Build: 15.0.4797.1000)

    And we can confirm that this is finally working again.


    Regards, Simon

    • Marked as answer by Simon-MCP Monday, March 14, 2016 9:48 AM
    Monday, March 14, 2016 9:47 AM

All replies

  • Hi Simon, 

    To narrow down the issue, I suggest you can check the ULS log for more detailed error information, it will be easier to troubleshooting.

    By default, SharePoint 2013 ULS log is located at the path:

    C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\LOGS

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Friday, October 30, 2015 3:44 AM
  • Hi Simon,

    Any Update ?

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, November 3, 2015 2:03 AM
  • Hello Jerry Zy,

    thanks for following up on this topic and sorry for the late reply but I was very busy the last days.

    We get the following errors in the ULS logs:

    FollowedContent.RefreshFollowedItem(item.Url=http://url, policy=Allow) : Local execution failed; Could not refresh followed item http://url: Exception: Value cannot be null.  Parameter name: serviceContext

    Could not follow the url http://url

    Microsoft.Office.Server.Social.SPSocialFollowingManager.Follow: Microsoft.Office.Server.UserProfiles.FollowedContentException: InternalError : Could not find item http://url     at Microsoft.Office.Server.UserProfiles.FollowedContent.RefreshFollowedItem(FollowedItem item, SPS2SAppExecutionPolicy policy)     at Microsoft.Office.Server.UserProfiles.FollowedContent.Follow(Uri url, FollowedItemData data)     at Microsoft.Office.Server.Social.SPSocialFollowingManager.FollowContent(Uri contentUri)     at Microsoft.Office.Server.Social.SPSocialFollowingManager.<>c__DisplayClass3.<Follow>b__2()     at Microsoft.Office.Server.Social.SPSocialUtil.InvokeWithExceptionTranslation[T](ISocialOperationManager target, String name, Func`1 func)



    Regards, Simon


    • Edited by Simon-MCP Wednesday, November 4, 2015 12:49 PM
    Wednesday, November 4, 2015 12:49 PM
  • Hi Simon,

    I suggest you can try to follow other sites to test if all the sites can't follow or the specific one. It will easier to narrow down the issue.

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Friday, November 6, 2015 2:22 AM
  • Hi Jerry,

    of course we already tried this before we posted here. We tried multiple sites and users.


    Regards, Simon

    Friday, November 6, 2015 8:08 AM
  • Hi,

    We have exactly similar issue here, previously Follow can work, but after applying NOV 2015 CU it throws error:

    Could not refresh followed item http://url: Exception: Value cannot be null.  Parameter name: serviceContext

    Anyone have solution to fix it?

    Thanks,

    Arie

    Thursday, November 26, 2015 2:20 AM
  • I am experiencing the same issue. 

    I have the same issue and I have October 2015 CU on that environment. 

    I have another  environment where I have May 2015 CU and its working just fine on that environment. The exact same code. 

    Any solution for this yet? 


    Tuesday, December 1, 2015 12:23 PM
  • A few weeks ago we opened an Microsoft Support Case about this problem.

    But so far we didn't got any solution for this...


    Regards, Simon

    Saturday, December 5, 2015 11:00 AM
  • Hey folks, any update on this issue, we're experiencing this as well. Thanks!

    Michael Mukalian | Jan 2010 - Dec 2010 MVP SharePoint Services | MCTS: MOSS 2007 Configuration | http://www.mukalian.com/blog

    Saturday, December 12, 2015 6:03 PM
  • Hi all,

    So this is a bug introduced by the September 2015 CU. That said, there's a workaround by setting HttpContext.Current. I'm using a console application to test, so I'm setting it via a custom method, but here's the code in it's entirety.

    using System;
    using System.Linq;
    using System.Web;
    using System.Web.Hosting;
    using Microsoft.Office.Server.Social;
    using Microsoft.Office.Server.UserProfiles;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Administration;
    
    namespace FollowedContentErr
    {
        internal class Program
        {
    
    
            private static void Main(string[] args)
            {
                UPA();
            }
    
            private static void UPA()
            {
                string siteurl = "http://spwebapp1/personal/userName";
                string username = "domain\\userName";
                string followurl = "http://spwebapp1/sites/targetSite";
    
                SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    try
                    {
                        using (SPSite site = new SPSite(siteurl))
                        {
                            SPWeb web = site.RootWeb;
                            web.AllowUnsafeUpdates = true;
                            SPServiceContext context = SPServiceContext.GetContext(site);
    
                            if (context != null)
                            {
                                UserProfileManager profileManager = new UserProfileManager(context);
    
                                if (profileManager.UserExists(username))
                                {
                                    UserProfile userProfile = profileManager.GetUserProfile(username);
                                    SPSocialFeedManager feedManager = new SPSocialFeedManager(userProfile, context);
                                    SPSocialFollowingManager followingManager = new SPSocialFollowingManager(userProfile,
                                        context);
                                    SPSocialActor[] followers = followingManager.GetFollowed(SPSocialActorTypes.Sites);
                                    SPSocialActor foundActor = null;
                                    try
                                    {
                                        foundActor = followers.First(f => f.ContentUri.ToString() == followurl);
    
                                    }
                                    catch (Exception)
                                    {
    
                                    }
                                    if (foundActor == null)
                                    {
     
                                        SPSocialActorInfo actor = new SPSocialActorInfo();
                                        actor.ActorType = SPSocialActorType.Site;
                                        actor.ContentUri = new Uri(followurl);
                                        SPServiceContext.GetContext(site);
                                        HttpContext.Current = FakeSharePointWorkerRequest.GetFakeHttpContextForSharePoint(site.RootWeb);
                                        
                                        followingManager.Follow(actor);
                                        web.AllowUnsafeUpdates = false;
                                    }
                                }
    
                            }
                        }
                    }
                    catch (Exception e)
                    {
                    }
                    finally
                    {
    
                    }
                });
            }
        }
    
        public class FakeSharePointWorkerRequest : SimpleWorkerRequest
        {
            private readonly string _ServerName;
     
            public FakeSharePointWorkerRequest(SPWeb web) : base(web.ServerRelativeUrl, web.Site.WebApplication.IisSettings[SPUrlZone.Default].Path.FullName, string.Empty, string.Empty, null)
            {
                _ServerName = web.Site.HostName;
            }
     
            public override string GetServerName()
            {
                return _ServerName;
            }
    
            public static HttpContext GetFakeHttpContextForSharePoint(SPWeb web)
            {
                FakeSharePointWorkerRequest workerRequest = new FakeSharePointWorkerRequest(web);
                HttpContext httpContext = new HttpContext(workerRequest);
                httpContext.Items["HttpHandlerSPWeb"] = web;
                httpContext.Items["HttpHandlerSPSite"] = web.Site;
    
                return httpContext;
            }
        }
    }


    Trevor Seward

            

    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    Sunday, December 13, 2015 12:56 AM
  • For a few days we got an answer from the Microsoft Support.

    They confirmed that this bug has been introduced with the September / October 2015 CU.

    This Bug should be fixed in the February 2016 CU.

    I will post another update as soon as we have installed this CU-Package.


    Regards, Simon

    Friday, January 15, 2016 7:51 PM
  • For a few days we got an answer from the Microsoft Support.

    They confirmed that this bug has been introduced with the September / October 2015 CU.

    This Bug should be fixed in the February 2016 CU.

    I will post another update as soon as we have installed this CU-Package.


    Regards, Simon

    FYI: Today we installed the SharePoint February 2016 CU in our farm. (Build: 15.0.4797.1000)

    And we can confirm that this is finally working again.


    Regards, Simon

    • Marked as answer by Simon-MCP Monday, March 14, 2016 9:48 AM
    Monday, March 14, 2016 9:47 AM