We've a Sharepoint 2010 application where we create user profile in AD programmatically, and then use that data from AD to further create a Sharepoint 2010 profile. Sometimes we get the following error:
Appreciate your help.
ERROR: System.ComponentModel.Win32Exception: No mapping between account names and security IDs was done_ at Microsoft.Office.Server.Utilities.Win32.AdvApi.LookupAccountName(String lpSystemName, String lpAccountName, IntPtr Sid, Int32& cbSid, StringBuilder ReferencedDomainName, Int32& cchReferencedDomainName, SID_NAME_USE& peUse)_
CODE:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(strSiteUrl))
{
site.AllowUnsafeUpdates = true;
UserProfile user = null;
HttpContext oldContext = HttpContext.Current;
SPServiceContext context = SPServiceContext.GetContext(site);
HttpContext.Current = null;
UserProfileManager currentUserProfileManager = new UserProfileManager(context);
bool userexist = false;
try
{
user = currentUserProfileManager.GetUserProfile(accountName);
userexist = true;
}
catch (Exception ex)
{
userexist = false;
}
if (currentUserProfileManager != null)
{
if (!userexist)
{
try
{
user = currentUserProfileManager.CreateUserProfile(accountName);
}
catch (Exception ex)
{
throw;
}
}
}
}
}
I think that it is impossible to create a user using sharepoint tools. You need to first create an account in AD using, for example, this: https://www.codeproject.com/Articles/90142/Everything-in-Active-Directory-via-C-NET-Using
And only then set up replication of profiles in the sharepoint