The 'username' argument is invalid. while connecting to SharePoint Online Manager
The 'username' argument is invalid. while connecting to SharePoint Online Manager
I am connecting to SharePoint Online Manager like this below:-
protected SharePointOnlineCredentials GetCredentials()
{
return new SharePointOnlineCredentials(this.UserName,
this.GetSecurePassword(this.Password));
}
I get an error saying - The 'username' argument is invalid.
Below is the SharePoint Online Credentials Class:-
#region Assembly Microsoft.SharePoint.Client.Runtime, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
// C:SourceCodePDS PortalJLL.PDSpackagesMicrosoft.SharePointOnline.CSOM.16.1.4727.1200libnet45Microsoft.SharePoint.Client.Runtime.dll
#endregion
using System;
using System.Net;
using System.Security;
namespace Microsoft.SharePoint.Client
{
public sealed class SharePointOnlineCredentials : ICredentials
{
public SharePointOnlineCredentials(string username, SecureString password);
public string UserName { get; }
public event EventHandler<SharePointOnlineCredentialsWebRequestEventArgs> ExecutingWebRequest;
public string GetAuthenticationCookie(Uri url);
public string GetAuthenticationCookie(Uri url, bool alwaysThrowOnFailure);
public NetworkCredential GetCredential(Uri uri, string authType);
}
}
Below is the Stack Trace. Any ideas ?
at Microsoft.SharePoint.Client.SharePointOnlineCredentials..ctor(String username, SecureString password)
at JLL.PDS.Data.SharePoint.SharePointOnlineManager.GetCredentials() in C:SourceCodePDS PortalJLL.PDSJLL.PDS.Data.SharePointSharePointOnlineManager.cs:line 71
at JLL.PDS.Data.SharePoint.SharePointOnlineManager.GetClientContext(String siteUrl) in C:SourceCodePDS PortalJLL.PDSJLL.PDS.Data.SharePointSharePointOnlineManager.cs:line 57
at JLL.PDS.Data.SharePoint.SharePointUserProfileManager.Initialize() in C:SourceCodePDS PortalJLL.PDSJLL.PDS.Data.SharePointSharePointUserProfileManager.cs:line 43
at JLL.PDS.Data.SharePoint.SharePointUserProfileManager.GetProfileImageData(Profile profile) in C:SourceCodePDS PortalJLL.PDSJLL.PDS.Data.SharePointSharePointUserProfileManager.cs:line 70
at JLL.PDS.Model.Services.ProfileSyncService.<SaveProfilesToTargetDataSource>d__6.MoveNext() in C:SourceCodePDS PortalJLL.PDSJLL.PDS.ModelServicesProfileSyncService.cs:line 106
1 Answer
1
It turns out that the username setting App.Config needed to be appended with the domain email. For example App Setting was XYZ, I had to make XYZ@abc.com. Not my fault as that was present in App.Config incorrectly. So whenever we get this error 'The 'username' argument is invalid.' that means we are sending the username incorrectly.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.