0
votes

We have a winforms app which pulls all lists from Office 365 SharePoint site. Recently I started getting error "user not found". I can login to the SP site https://[name].sharepoint.com/sites/[folder1]/[userfolder]/SitePages/Home.aspx from browser and see all lists. However when I run the winforms app, it throws error.

MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper(sharePointSite, sharePointUser, sharePointPassword);
ClientContext clientContext = new ClientContext(sharePointSite);
clientContext.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;
clientContext.Load(clientContext.Web);
clientContext.ExecuteQuery();    
Web web = clientContext.Web;

// Retrieve all lists from the server. 
clientContext.Load(web.Lists);

clientContext.ExecuteQuery(); //<-- Throws error here 

Error

    Message "User cannot be found." string
    ServerErrorCode -2146232832 int
    ServerErrorDetails  null    object
    ServerErrorTraceCorrelationId   "ee687f9d-c05a-2000-2113-22de7e4f8fe1"  string
    ServerErrorTypeName "Microsoft.SharePoint.SPException"  string
    ServerErrorValue    null    string
    ServerStackTrace    ""  string

Similar (didn't help) : Sharepoint 2010 user not found error

I am fetching lists, not sure if this is related. : https://social.technet.microsoft.com/Forums/office/en-US/f9221c7b-f835-4041-ac21-ab896bae106f/microsoftsharepointspexception-user-cannot-be-found?forum=sharepointgeneralprevious

Help/suggestions much appreciated! Thank you!

2
Have you tried retrieving all the users from the Sharepoint site via WinForms? It is possible the variables you are sending MsOnlineClaimsHelper have issues and because of that the Sharepoint query is executing but for some reason the user isn't being found. - jaredbaszler
Thanks @jaredbaszler for your reply! User could login successfully but not fetch any lists. I have tried link as well. I can fetch some other information like site title/other details but not list. - DoodlerX

2 Answers

0
votes

Two options to fix the issue (if the first does not work try the second):

  1. User owner= web.ensureuser(domain\\username)

  2. User owner=web.CurrentUser;

0
votes

You missed the credentials

NetworkCredential credentials = new NetworkCredential("domain\\user", "password");
context.Credentials = credentials;