question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] FilePicker throws System.InvalidOperationException: 'Window Not Found'

See original GitHub issue

Description

In maui preview7 on android, whenever call FilePicker.PickAsync(); method the maui application will throw System.InvalidOperationException: 'Window Not Found' and crash.

Steps to Reproduce

  1. create a new maui app using default maui templat
  2. setup permissions and call platform init on android
  3. add await FilePicker.PickAsync(); in button onclick event handler and start debug
  4. click the button

Expected Behavior

the filepicker shows up

Actual Behavior

the filepicker shows up, then the app throws System.InvalidOperationException: 'Window Not Found' and crash.

Basic Information

  • Version with issue: maui preview7
  • Last known good version: maui preview6
  • IDE: VIsual Studio 2022 preview 3
  • Platform Target Frameworks:
    • iOS:
    • Android:
    • UWP:
  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:android

Screenshots

image

Reproduction Link

https://github.com/Chronostasys/ButtonTest

Workaround

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
josephatkuviocommented, Aug 15, 2021

I am seeing the same issue on Preview 7 on Android, in my case when attempting to open a custom tab via MSAL.NET. I’ve tried with the embedded browser as well, same issue, so it seems to be related to the launching of any new activity, or more specifically, the default MAUI OnResume callbacks. Here is a full stack trace upon crash. It appears that something in the MAUI OnResume handlers could be passing the wrong Window object up the chain?

08-13 16:04:20.222 22816 22816 D AndroidRuntime: Shutting down VM
08-13 16:04:20.223 22816 22816 E AndroidRuntime: FATAL EXCEPTION: main
08-13 16:04:20.223 22816 22816 E AndroidRuntime: android.runtime.JavaProxyThrowable: System.InvalidOperationException: Window Not Found
08-13 16:04:20.223 22816 22816 E AndroidRuntime:    at Microsoft.Maui.ContextExtensions.GetWindow(Context context) in Microsoft.Maui.dll:token 0x60001ad+0x7f
08-13 16:04:20.223 22816 22816 E AndroidRuntime:    at Microsoft.Maui.LifecycleEvents.AppHostBuilderExtensions.<>c.<OnConfigureLifeCycle>b__1_2(Activity activity) in Microsoft.Maui.dll:token 0x6000996+0x0
08-13 16:04:20.223 22816 22816 E AndroidRuntime:    at Microsoft.Maui.MauiApplication.ActivityLifecycleCallbacks.<>c__DisplayClass2_0.<OnActivityResumed>b__0(OnResume del) in Microsoft.Maui.dll:token 0x6000ab6+0x0
08-13 16:04:20.223 22816 22816 E AndroidRuntime:    at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[OnResume](IServiceProvider services, Action`1 action) in Microsoft.Maui.dll:token 0x60004d5+0x1d
08-13 16:04:20.223 22816 22816 E AndroidRuntime:    at Microsoft.Maui.MauiApplication.ActivityLifecycleCallbacks.OnActivityResumed(Activity activity) in Microsoft.Maui.dll:token 0x6000887+0x1b
08-13 16:04:20.223 22816 22816 E AndroidRuntime:    at Android.App.Application.IActivityLifecycleCallbacksInvoker.n_OnActivityResumed_Landroid_app_Activity_(IntPtr jnienv, IntPtr native__this, IntPtr native_activity) in Mono.Android.dll:token 0x602506c+0xf
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at crc6488302ad6e9e4df1a.MauiApplication_ActivityLifecycleCallbacks.n_onActivityResumed(Native Method)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at crc6488302ad6e9e4df1a.MauiApplication_ActivityLifecycleCallbacks.onActivityResumed(MauiApplication_ActivityLifecycleCallbacks.java:74)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.Application.dispatchActivityResumed(Application.java:436)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.Activity.dispatchActivityResumed(Activity.java:1379)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.Activity.onResume(Activity.java:1905)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1456)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.Activity.performResume(Activity.java:8135)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4434)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4476)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:106)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:223)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7656)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
08-13 16:04:20.223 22816 22816 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

At the moment the new activity is created, the following log code added to OnResume:

Android.Util.Log.Info("", "Activity is " + activity);
Android.Util.Log.Info("", "Window is " + activity.Window);
Android.Util.Log.Info("", "Context is " + activity.GetWindow());

returns this:

08-15 13:54:11.991  4878  4878 I: Activity is crc647e7a282969979595.MainActivity@d9db2e9
08-15 13:54:11.998  4878  4878 I: Window is com.android.internal.policy.PhoneWindow@777de97
08-15 13:54:11.998  4878  4878 I: Context is Microsoft.Maui.Controls.Window

I do see new PR activity around CreateWindow in #2035 by @mattleibow, but it didn’t make it into Preview 7, and seems to revolve around more of an app launch timing issue than anything.

2reactions
RNublacommented, Oct 14, 2021

This bug still persist on preview 9. Is there a temporary workaround atm? Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# WinUI 3 I cannot use the file specified from a ...
C# WinUI 3 I cannot use the file specified from a FileSavePicker dialog to create an excel report file - Stack Overflow.
Read more >
"File Picker UI Host has stopped working" error in every ...
The error message of "File Picker UI Host has stopped working" pops up every time after the splash screen; it's benign but annoying....
Read more >
Changelog | Input System | 1.7.0
Fixed the "Release tests throws exception in InputSystem" bug (case ISXB-581). Fixed issues with generating Precompiled Layouts for devices which are not ......
Read more >
TriLib - Model Loading Package | Page 25
An error ocurred while loading your Model: System. ... throw new Exception($"File {originalFilename} not found.");.
Read more >
Open file picker interface programatically on xamarin android
My Droid Packagemap has no visible packages (deleted them all) and when I try to add a new version of Xamarin it gives...
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