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

InvalidCastException in Xamarin.RangeSlider.RangeSliderControl.OnRestoreInstanceState #166

Open
joshsutterfield opened this issue Jul 17, 2020 · 1 comment

Comments

@joshsutterfield
Copy link

Unable to duplicate but have seen InvalidCastException logged in crashes coming from here. Most likely one of the two casts is casting null. Cannot fix or bypass with override since Android requires base.OnRestoreInstanceState to be called.

        protected override void OnRestoreInstanceState(IParcelable parcel)
        {
            Bundle bundle = (Bundle)parcel;
            base.OnRestoreInstanceState((IParcelable)bundle.GetParcelable("SUPER"));
            NormalizedMinValue = bundle.GetFloat("MIN");
            NormalizedMaxValue = bundle.GetFloat("MAX");
        }

Suggest alternate code:

            if (parcel is Bundle bundle)
            {
                base.OnRestoreInstanceState(bundle.GetParcelable("SUPER") as IParcelable);
                NormalizedMinValue = bundle.GetFloat("MIN");
                NormalizedMaxValue = bundle.GetFloat("MAX");
            }
            else
            {
                base.OnRestoreInstanceState(parcel);
            }
@halkar
Copy link
Owner

halkar commented Sep 7, 2020

Can you provide a sample project to reproduce the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants