System.InvalidOperationException: On Xamarin.Android, you have to specify the current Activity from which the browser pop-up will be displayed using the WithParentActivityOrWindow method.

See original GitHub issue

On executing this line authResult = await App.PCA.AcquireTokenInteractive(App.Scopes) .WithParentActivityOrWindow(App.ParentWindow) .ExecuteAsync();

It is throwing Exception:

05-22 14:32:40.165 E/mono (29592): 05-22 14:32:40.165 E/mono (29592): Unhandled Exception: 05-22 14:32:40.165 E/mono (29592): System.InvalidOperationException: On Xamarin.Android, you have to specify the current Activity from which the browser pop-up will be displayed using the WithParentActivityOrWindow method. 05-22 14:32:40.165 E/mono (29592): at Microsoft.Identity.Client.AcquireTokenInteractiveParameterBuilder.Validate () [0x00018] in <48941809037546559a7e7308bdd45147>:0 05-22 14:32:40.165 E/mono (29592): at Microsoft.Identity.Client.AbstractAcquireTokenParameterBuilder1[T].ValidateAndCalculateApiId () [0x00000] in <48941809037546559a7e7308bdd45147>:0 05-22 14:32:40.165 E/mono (29592): at Microsoft.Identity.Client.AbstractPublicClientAcquireTokenParameterBuilder1[T].ExecuteAsync (System.Threading.CancellationToken cancellationToken) [0x00000] in <48941809037546559a7e7308bdd45147>:0 05-22 14:32:40.165 E/mono (29592): at Microsoft.Identity.Client.AbstractAcquireTokenParameterBuilder1[T].ExecuteAsync () [0x00006] in <48941809037546559a7e7308bdd45147>:0 05-22 14:32:40.165 E/mono (29592): at Variance.ViewModels.MainPageViewModel+<OnSignInSignOut>d__12.MoveNext () [0x00285] in C:\Mobility\test\Variation\App\Variance\Variance\ViewModels\MainPageViewModel.cs:78 05-22 14:32:40.165 E/mono (29592): --- End of stack trace from previous location where exception was thrown --- 05-22 14:32:40.165 E/mono (29592): at (wrapper dynamic-method) System.Object.24(intptr,intptr) 05-22 14:32:40.165 E/mono (29592): at (wrapper native-to-managed) System.Object.24(intptr,intptr) 05-22 14:32:40.172 E/mono-rt (29592): [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: On Xamarin.Android, you have to specify the current Activity from which the browser pop-up will be displayed using the WithParentActivityOrWindow method. 05-22 14:32:40.172 E/mono-rt (29592): at Microsoft.Identity.Client.AcquireTokenInteractiveParameterBuilder.Validate () [0x00018] in <48941809037546559a7e7308bdd45147>:0 05-22 14:32:40.172 E/mono-rt (29592): at Microsoft.Identity.Client.AbstractAcquireTokenParameterBuilder1[T].ValidateAndCalculateApiId () [0x00000] in <48941809037546559a7e7308bdd45147>:0 05-22 14:32:40.172 E/mono-rt (29592): at Microsoft.Identity.Client.AbstractPublicClientAcquireTokenParameterBuilder1[T].ExecuteAsync (System.Threading.CancellationToken cancellationToken) [0x00000] in <48941809037546559a7e7308bdd45147>:0 05-22 14:32:40.172 E/mono-rt (29592): at Microsoft.Identity.Client.AbstractAcquireTokenParameterBuilder1[T].ExecuteAsync () [0x00006] in <48941809037546559a7e7308bdd45147>:0 05-22 14:32:40.172 E/mono-rt (29592): at Variance.ViewModels.MainPageViewModel+<OnSignInSignOut>d__12.MoveNext () [0x00285] in C:\Mobility\test\Variation\App\Variance\Variance\ViewModels\MainPageViewModel.cs:78 05-22 14:32:40.172 E/mono-rt (29592): — End of stack trace from previous location where exception was thrown — 05-22 14:32:40.172 E/mono-rt (29592): at (wrapper dynamic-method) System.Object.24(intptr,intptr) 05-22 14:32:40.172 E/mono-rt (29592): at (wrapper native-to-managed) System.Object.24(intptr,intptr)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
jennyf19commented, Jul 2, 2020

@lorne-olo glad you got android sorted out. @aiwangmicrosoft Can you help make sure the docs/sample code are the same? thank you.

For iOS, do you have all the provisioning profile information set up? I think you have to have it connected to a Mac to get it to work and provision correctly.

1reaction
jmprieurcommented, Nov 11, 2019

Thanks for confirming, @robiharid. Closing. cc: @jennyf19

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xamarin Android App error when authenticating
In the code below, the OnActivityResult in MainActivity is called (I have a breakpoint), but control is never returned to the line after ......
Read more >
Xamarin Android code configuration and troubleshooting ...
When the interactive portion of the authentication flow ends, return control to MSAL by overriding the Activity . OnActivityResult() method.
Read more >
Authenticate your Xamarin applications using ...
In this tutorial I'm going to show you how to authenticate your Xamarin applications using the Microsoft authentication system.
Read more >
Implementing MSAL authentication in Xamarin.Forms
In the screenshot above I set the app to be publicly accessible using Azure AD accounts and personal Microsoft accounts. Click the Register ......
Read more >
Activities - Xamarin Android Guide - Peruzal
Implicit intent: Used to start activities without specifying the fully qualified name. The system will use the default registered activity or show options ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found