Getting 'Unknown error' while retrieving user profiles properties in SharePoint Online CSOM

Julien St-Pierre Fortin 1 Reputation point
2022-08-12T18:41:29.357+00:00

I am trying to fetch user properties for a bunch of profiles and at some point (after couple of thousands of users), I am getting either:

Microsoft.SharePoint.Client.ServerException: Unknown Error
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()

OR

Microsoft.SharePoint.Client.ServerException: Object reference not set to an instance of an object.
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()

The code I am running looks like this:

  var peopleManager = new PeopleManager(context);  
  
  foreach (string userName in GetUserNames())  
  {  
       PersonProperties props = peopleManager.GetPropertiesFor(userName);  
       context.Load(props);  
  }  
  
context.ExecuteQuery()  

Each query will have 100 user props loaded. Also I am disposing the context between batches.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
8,128 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,278 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 24,531 Reputation points Microsoft Vendor
    2022-08-16T06:13:31.59+00:00

    Hi @Julien St-Pierre Fortin ,
    Please refer to following code to get PersonProperties

        string serverUrl = "http://serverName/";    
        string targetUser = "domainName\\\\userName";    
    
        // Connect to the client context.  
        ClientContext clientContext = new ClientContext(serverUrl);  
    
        // Get the PeopleManager object and then get the target user's properties.  
        PeopleManager peopleManager = new PeopleManager(clientContext);  
        PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser);  
    
        clientContext.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);  
        clientContext.ExecuteQuery();  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

  2. Julien St-Pierre Fortin 1 Reputation point
    2022-08-16T13:51:56.067+00:00

    Ok thanks @RaytheonXie_MSFT !

    I am wondering though, why is this failing in the first place and how your snippet would solve this issue?


  3. Felix Pelletier 6 Reputation points
    2022-08-18T15:05:04.713+00:00

    Hi! I'm on @Julien St-Pierre Fortin 's team.

    The same code Julien posted worked on August 9th (EDIT: it even worked on the 11th), and fails with an unknown error from the 12th on.

    It was failing on one of our customer's instance, now it's failing on our own.
    I believe a recent update might have broken something, and seeing that 17 people are following this question, I think we might not be alone.

    Anybody else having the same issue?

    0 comments No comments