Symptoms
When forms in our solution are initializing and attempting to interact with SharePoint document libraries an error is thrown in the browser and logged to the Host Server log files.
"9394705","2015-12-14 08:53:58","Error","SmartObjects","10702","Error","SourceCode.SmartObjects.ServiceBroker rExecuteSmartObject]","10702 An error occurred in the collaborate_crbard_com Service Instance. The remote server returned an error: (401) Unauthorized.Failed to initialize the Context:
URL: {SPSIteURL}
Username:
Error Details: Method: SharePointService.initializeContext
x-ms-diagnostics : 3001000reason='There has been an error authenticating the request.'category='invalid_client'
SPRequestGuid : 212f4b9d-4c34-a0c3-5715-865328a1df27
","anonymous","0.0.0.0","{machinename}:C:Program Files (x86)K2 blackpearlHost ServerBin","9393345","4f5b1fe04d804449bf0c3bf5188532bf",""
Diagnoses
We've seen this error quite a bit when there are multiple user profiles in the UPA where the 'SPS-UserPrincipalName' value is the same.
In this particular case, the configuration for the environment was as below:
1 SQL Server, 2 K2 Servers, 3 SP Server and a load balancer.
Resolution
It was determined that the User Profile Service was not running on any of the 3 SP Farm Servers. The service was started on the APP server, and waited 15-20 minutes for profiles to populate and the error went away. However this did not completely resolve the issue.
In the end a User Profile Sync connection was added to the SharePoint farm where the issue was occurring, and the error no longer surfaced after that.