Which Version of ADAL are you using ?
ADAL 3.18.0 and later
Which platform has the issue?
net462
What authentication flow has the issue?
Other? - please describe;
Repro
Create new WinForms project targeting .NET 462 and add the following code to handle Load event.
private async void Form1_Load(object sender, EventArgs e)
{
WindowState = FormWindowState.Normal;
//fill in as necessary for correct auth
const string resource = "https://www.myresource.com/";
const string clientId = "client_id_guid";
const string redirectUri = "https://myredirecturi";
const string authority = "https://login.windows.net/myauthority/oauth2/token";
var context = new AuthenticationContext(authority, true, TokenCache.DefaultShared);
var result = await context.AcquireTokenAsync(resource, clientId,
new Uri(redirectUri),
new PlatformParameters(PromptBehavior.SelectAccount, this));
}
Expected behavior
Windows form is shown in the background with the browser login window in the foreground. The browser login window is the child of the windows form.
Actual behavior
Exception is thrown:
System.InvalidOperationException: 'Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on.'
Possible Solution
Additional context/ Logs / Screenshots
WindowsFormsApp1.zip
If you downgrade the library to 3.17.3 there is no issue with the cross-threading.