microsoft-authentication-library-for-dotnet: Due to MonoAndroid9.0, MSAL 3.0.0 Preview Throws System.PlatformNotSupportedException on Xamarin Forms App which target MonoAndroid8.1
Which Version of MSAL are you using ? MSAL 3.0.0-preview
Platform Xamarin Forms, testing with Android on Pixel 3 XL
What authentication flow has the issue?
- Desktop / Mobile
- [ x] Interactive
- Integrated Windows Auth
- Username Password
- Device code flow (browserless)
- Web App
- Authorization code
- OBO
- Web API
- OBO
Other? - please describe;
Is this a new or existing app?
c. This is a new app or experiment
Repro Created a brand new Xamarin Forms app in VS 2019 and install MSAL 3.0.0-Preview in all 3 projects.
Used the fluent api to build
PCA = PublicClientApplicationBuilder.Create(ClientID).Build();
Added the example code from here
Debug the Application.
Expected behavior The authentication flow runs throw the browser and logs the user in.
Actual behavior The following call throws an exception
result = await App.PCA.AcquireTokenInteractive(App.Scopes, null).ExecuteAsync();
Unhandled Exception: System.PlatformNotSupportedException: Possible Cause: If you are using an XForms app, or generally a netstandard assembly, make sure you add a reference to Microsoft.Identity.Client.dll from each platform assembly (e.g. UWP, Android, iOS), not just from the common netstandard assembly
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (4 by maintainers)
@jennyf19 Thank you, that solved it. I had the following line commented out, probably when I was trying to diagnose on my own.
AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data);
Thank you everyone for your assistance.
The bigger “cons” of leaving MonoAndroid 9 is supportability, because if your app is MonoAndroid8.1, the failure is very cryptic. We should at least provide a better exception.
I am also wary about developers actually wanting to target only 9, because Android API level x (Pie) has not yet gained widespread use.
I’ll look into this.
@napoleonjones Hurray! thanks for the quick update! Glad you know you got it sorted out.
We still have not decided what we will do w/the original issue
Let’s stick to having everything to 9.0 if that works for others.
As suggested by @bgavrilMS, I was able to change the target framework version in the Android.csproj file from 8.1 to:
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
and that worked (of course passing in an Activity for the parent window in the AT interactive call). @napoleonjones Could you verify changing the target framework to v9.0 works for you with MSAL v3?The default target framework in VS when making a new Xamarin Forms project is 8.1 and we are targeting 9. So…do we want to move back to 8.1? That will require a little work, and @MarkZuber listed our reasons for targeting 9. Or do we document this and ask the customer to target 9.0? @jmprieur @henrik-me
@napoleonjones thanks for the log…will hopefully have an update for you tomorrow. you can use 2.7.1 in the meantime.