Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Chronostasys opened this issue Aug 14, 2021 · 8 comments · Fixed by #3232
Closed

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

Chronostasys opened this issue Aug 14, 2021 · 8 comments · Fixed by #3232
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-6.0.200-preview.12 Look for this fix in 6.0.200-preview.12! t/bug Something isn't working

Comments

@Chronostasys
Copy link

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

@josephatkuvio
Copy link

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.

@PaulSorauer-IPG
Copy link

+1 from me.

I'm getting the issue when trying to acquire a token using MSAL.NET in Microsoft.Identity.Client v.4.35.1 (which was working fine in Preview 6).

More details supplied in #2154 - #2154 (comment)

Cheers,

Paul

@rabberbock
Copy link

rabberbock commented Aug 20, 2021

Same here with WebAuthenticator

Time	Device Name	Type	PID	Tag	Message
08-20 12:57:40.885	Samsung SM-G991U	Error	31165	AndroidRuntime	android.runtime.JavaProxyThrowable: System.InvalidOperationException: Window Not Found
   at Microsoft.Maui.ContextExtensions.GetWindow(Context context) in Microsoft.Maui.dll:token 0x60001ad+0x7f
   at Microsoft.Maui.LifecycleEvents.AppHostBuilderExtensions.<>c.<OnConfigureLifeCycle>b__1_2(Activity activity) in Microsoft.Maui.dll:token 0x6000996+0x0
   at Microsoft.Maui.MauiApplication.ActivityLifecycleCallbacks.<>c__DisplayClass2_0.<OnActivityResumed>b__0(OnResume del) in Microsoft.Maui.dll:token 0x6000ab6+0x0
   at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[OnResume](IServiceProvider services, Action`1 action) in Microsoft.Maui.dll:token 0x60004d5+0x1d
   at Microsoft.Maui.MauiApplication.ActivityLifecycleCallbacks.OnActivityResumed(Activity activity) in Microsoft.Maui.dll:token 0x6000887+0x1b
   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
   at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in Java.Interop.dll:token 0x600055b+0x8e
   at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters) in Java.Interop.dll:token 0x60005ea+0x63
   at Android.App.Activity.OnResume() in Mono.Android.dll:token 0x6015187+0xa
   at Microsoft.Maui.Essentials.WebAuthenticatorIntermediateActivity.OnResume() in Microsoft.Maui.Essentials.dll:token 0x600041c+0x0
   at Android.App.Activity.n_OnResume(IntPtr jnienv, IntPtr native__this) in Mono.Android.dll:token 0x6015186+0x8
	at crc64192d9de59b079c6d.WebAuthenticatorIntermediateActivity.n_onResume(Native Method)
	at crc64192d9de59b079c6d.WebAuthenticatorIntermediateActivity.onResume(WebAuthenticatorIntermediateActivity.java:40)
	at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1456)
	at android.app.Activity.performResume(Activity.java:8344)
	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4854)
	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4901)
	at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:246)
	at android.app.ActivityThread.main(ActivityThread.java:8512)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

It worked on preview 6, but not on 7.

@mattleibow
Copy link
Member

Having a look at that stack trace I think we fixed that shortly after releasing P7.
Previously we assumed there was always Window since you started from one. But in some cases, this was not true.

It should be fixed in RC1. You can test out the current CI builds using this Wiki:
https://github.com/dotnet/maui/wiki/Installing-.NET-6

@mattleibow mattleibow added this to the 6.0.100-rc.1 milestone Aug 25, 2021
@PaulSorauer-IPG
Copy link

Having a look at that stack trace I think we fixed that shortly after releasing P7.
Previously we assumed there was always Window since you started from one. But in some cases, this was not true.

It should be fixed in RC1. You can test out the current CI builds using this Wiki:
https://github.com/dotnet/maui/wiki/Installing-.NET-6

As an FYI - in case it helps anyone, I have some notes I made on installing the CI build of RC1 here.

@Rowingwolf
Copy link

I believe I'm seeing the same issue when calling MediaPicker.CapturePhotoAsync(). I'll probably wait until RC1 is released. I'm assuming it should be out in the next week or so.

Am surprised this one made it into the wild because it impacts such a wide range of calls.

@Eilon Eilon added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Sep 16, 2021
@RNubla
Copy link

RNubla commented Oct 14, 2021

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

@jsuarezruiz jsuarezruiz added the t/bug Something isn't working label Oct 22, 2021
@pwkiel
Copy link

pwkiel commented Dec 1, 2021

I too am experiencing issues with this still. I see its still being tracked open and that there is a link to a fix. Is that fix set to go live later this month when preview 11 comes out?

@ghost ghost locked as resolved and limited conversation to collaborators Feb 19, 2022
@samhouts samhouts added the fixed-in-6.0.200-preview.12 Look for this fix in 6.0.200-preview.12! label Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-6.0.200-preview.12 Look for this fix in 6.0.200-preview.12! t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.