Hi!
We are currently porting our XAMARIN apps to MAUI and are stuck on an issue.
We have a feature that works more or less like this:
- a user gets a mail with a link and clicks it
- the browser opens and a website redirects to the installed app to perform a registration.
When the app is completely shut down, the redirect seems to work normally -> starts app and app runs normally.
But when the app is running in the background, after clicking the link the app goes into foreground and crashes with this error:
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: MauiContext is null.
[mono-rt] at Microsoft.Maui.Controls.Window.get_MauiContext() in D:\a\_work\1\s\src\Controls\src\Core\Window\Window.cs:line 336
[mono-rt] at Microsoft.Maui.Controls.Platform.AlertManager.Subscribe(Window window) in D:\a\_work\1\s\src\Controls\src\Core\Platform\AlertManager\AlertManager.Android.cs:line 28
[mono-rt] at Microsoft.Maui.Controls.Platform.AlertManager.Subscribe() in D:\a\_work\1\s\src\Controls\src\Core\Platform\AlertManager\AlertManager.cs:line 13
[mono-rt] at Microsoft.Maui.Controls.Window.OnPageHandlerChanged(Object sender, EventArgs e) in D:\a\_work\1\s\src\Controls\src\Core\Window\Window.cs:line 652
[mono-rt] at Microsoft.Maui.Controls.Window.OnPageChanged(Page oldPage, Page newPage) in D:\a\_work\1\s\src\Controls\src\Core\Window\Window.cs:line 640
[mono-rt] at Microsoft.Maui.Controls.Window.<>c.<.cctor>b__219_0(BindableObject b, Object o, Object n) in D:\a\_work\1\s\src\Controls\src\Core\Window\Window.cs:line 26
[mono-rt] at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 633
[mono-rt] at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 559
[mono-rt] at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 464
[mono-rt] at Microsoft.Maui.Controls.Window.set_Page(Page value) in D:\a\_work\1\s\src\Controls\src\Core\Window\Window.cs:line 122
[mono-rt] at Microsoft.Maui.Controls.Window..ctor(Page page) in D:\a\_work\1\s\src\Controls\src\Core\Window\Window.cs:line 106
[mono-rt] at Access.MA.CredentialHolderApp.App.CreateWindow(IActivationState activationState) in C:\Projects
et8\Access.MobileAccess\MauiApps\MobileAccess\src\Access.MA.CredentialHolderApp\App.xaml.cs:line 52
[mono-rt] at Microsoft.Maui.Controls.Application.Microsoft.Maui.IApplication.CreateWindow(IActivationState activationState) in D:\a\_work\1\s\src\Controls\src\Core\Application\Application.cs:line 428
[mono-rt] at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Activity activity, IApplication application, Bundle savedInstanceState) in D:\a\_work\1\s\src\Core\src\Platform\Android\ApplicationExtensions.cs:line 46
[mono-rt] at Microsoft.Maui.MauiAppCompatActivity.OnCreate(Bundle savedInstanceState) in D:\a\_work\1\s\src\Core\src\Platform\Android\MauiAppCompatActivity.cs:line 35
[mono-rt] at Access.MA.CredentialHolderApp.MainActivity.<>n__0(Bundle savedInstanceState)
[mono-rt] at Access.MA.CredentialHolderApp.MainActivity.OnCreate(Bundle savedInstanceState) in C:\Projects
et8\Access.MobileAccess\MauiApps\MobileAccess\src\Access.MA.CredentialHolderApp\Platforms\Android\MainActivity.cs:line 50
[mono-rt] at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
[mono-rt] at Android.App.SyncContext.<>c__DisplayClass2_0.<Post>b__0() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:line 36
[mono-rt] at Java.Lang.Thread.RunnableImplementor.Run() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:line 36
[mono-rt] at Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Java.Lang.IRunnable.cs:line 84
[mono-rt] at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 26
The according code lines are:
MainActivity:
:
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density),
IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = App.DataScheme)]
public class MainActivity : MauiAppCompatActivity
{
:
protected override async void OnCreate(Bundle savedInstanceState)
{
FormsContext = this;
base.OnCreate(savedInstanceState); // <-- line 50
:
and
App.xaml.cs:
protected override Window CreateWindow(IActivationState activationState)
{
Page shell = IPlatformApplication.Current.Services.GetService<AppShell>();
return new Window(shell); // <-- line 52
}
It is a giant solution written by another team and I have no idea where else I should look or what info I could provide. Do you maybe have an idea what could cause this?