Rg.Plugins.Popup icon indicating copy to clipboard operation
Rg.Plugins.Popup copied to clipboard

Unhandled exception: InvalidCastException in PopupPageRenderer.OnDetachedFromWindow

Open wtheronjones opened this issue 4 years ago • 6 comments

🐛 Bug Report

My application is crashing because of an unhandled exception inside of PopupPageRenderer.OnDetachedFromWindow.

We need to add a try/catch around this code and in all the places in PopupPageRenderer where the same cast is performed to avoid app crashes(have seen this exact invalid cast exception before, but at a different method).

Existing code is as follows:

protected override void OnDetachedFromWindow()
        {
            Device.StartTimer(TimeSpan.FromMilliseconds(0), () =>
            {
                Popup.Context.HideKeyboard(((Activity) Popup.Context).Window.DecorView);
                return false;
            });
            base.OnDetachedFromWindow();
        }

This is from my logs:| 020-07-10 17:27:29.225 | 1117649352 | FATAL | AndroidEnvironment.UnhandledException: Handled: False, Exception: System.InvalidCastException: Specified cast is not valid. at Rg.Plugins.Popup.Droid.Renderers.PopupPageRenderer+<>c.<OnDetachedFromWindow>b__11_0 () [0x0000a] in <2c84bcd5850d4629957fe969f92dd4e6>:0 at Xamarin.Forms.Forms+AndroidPlatformServices+<>c__DisplayClass23_0.<StartTimer>b__0 () [0x00000] in :0 at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in :0 at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in :0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.44(intptr,intptr)

Expected behavior

Don't crash the app.

Reproduction steps

Unsure of how to reproduce.

Configuration

Version: 1.1.5.188

Platform:

  • [ ] :iphone: iOS
  • [ X] :robot: Android
  • [ ] :checkered_flag: WPF
  • [ ] :earth_americas: UWP
  • [ ] :apple: MacOS
  • [ ] :tv: tvOS
  • [ X] :monkey: Xamarin.Forms

wtheronjones avatar Jul 15 '20 18:07 wtheronjones

@wtheronjones Does this error appear on the latest version?

LuckyDucko avatar Sep 07 '20 00:09 LuckyDucko

I’ve since forked the project locally(very recently) and added a try/catch in the right spot, so I couldn’t tell you.

Sent from my iPhone

On Sep 6, 2020, at 5:59 PM, Tyson Elliot Hooker [email protected] wrote:

 @wtheronjones Does this error appear on the latest version?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

wtheronjones avatar Sep 07 '20 01:09 wtheronjones

Can you make a PR?

martijn00 avatar Oct 05 '20 10:10 martijn00

This still seems to be an issue. EDIT: I made a help issue for the problems I was encountering: #641

JesperNJessen avatar Feb 05 '21 10:02 JesperNJessen

Hi o am having the dame on uwp, with a recent downloaded version. There is some fix?

pabloat81 avatar May 31 '22 23:05 pabloat81

same issue for me

Hrishikesh46779 avatar Sep 07 '22 18:09 Hrishikesh46779