csharpq / IdentityServer4-XamarinOIDC

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NullPointerException on Client Login / LoginRequest

Helluva3ngineer opened this issue · comments

Thank you so much for contributing this project. I verified that it works then tried to carefully adapt it to another Xamarin forms app that I am writing. I'm testing using an Android emulator (which worked for your project.) When I get to the point of invoking this:

var result = await _oidcClient.LoginAsync(new LoginRequest());

I get the following exception:

Java.Lang.NullPointerException
Message=Attempt to invoke virtual method 'void android.content.Context.startActivity(android.content.Intent, android.os.Bundle)' on a null object reference

I'm no expert when it comes to debugging Java. Any ideas of a starting point on figuring this out? Thanks so much.

I just realized that _context is null on the ChromeCustomTabsBrowser implementation:

customTabsIntent.LaunchUrl(_context, Android.Net.Uri.Parse(options.StartUrl));

...which implies that CrossCurrentActivity.Current.Activity is not being set. I did add the MainApplication class.

So it looks like my version of CurrentActivityPlugin is newer. According to the new documentation, this does nothing:
CrossCurrentActivity.Current.Activity = activity;

Apparently the new syntax is:
public override void OnCreate() { base.OnCreate(); CrossCurrentActivity.Current.Init(this); }
I hope this helps someone else.