xamarin / XamarinCommunityToolkit

The Xamarin Community Toolkit is a collection of Animations, Behaviors, Converters, and Effects for mobile development with Xamarin.Forms. It simplifies and demonstrates common developer tasks building iOS, Android, and UWP apps with Xamarin.Forms.
MIT License
1.58k stars 471 forks source link

[Bug] Provided VisualElement cannot be parent to SnackBar Parameter name: sender #1556

Open sasukevita opened 3 years ago

sasukevita commented 3 years ago

Description

DisplayToastAsync() is worked, after closing app and reopen app from float service button, DisplayToastAsync() is shown but app crash

Toast.MakeText() still worked fine even after reopen app from float service button

Steps to Reproduce

  1. Create App with float service button
  2. Execute Toast (Worked)
    await this.DisplayToastAsync(options);
  3. Execute float service button
  4. Close App
  5. Reopen App from float service button
  6. Execute Toast (Crash)
    await this.DisplayToastAsync(options);

    Error Debug:

    [StaticLayout] maxLineHeight should not be -1.  maxLines:10 lineCount:10
    **System.ArgumentException:** 'Provided VisualElement cannot be parent to SnackBar
    Parameter name: sender'

Expected Behavior

no crash

Actual Behavior

Snackbar Toast is shown but then app crash

Basic Information

Workaround

try { await this.DisplayToastAsync(options); } catch {}
VladislavAntonyuk commented 3 years ago

Could you please attach a small project to reproduce the issue

jfversluis commented 3 years ago

@sasukevita as mentioned a reproduction project would be super helpful. Thanks!

VladislavAntonyuk commented 3 years ago

What I found from the code, that we are not able to get the XF renderer for the VisualElement. If you are not calling the method from XF, I think it won't work.

ThomasBernardPageUp commented 2 years ago

You call DisplaySnackBarAsync from a page that is not the MainPage. You should do : App.Current.MainPage.DisplaySnackBarAsync( )

I had the same problem and this fixed it