XamarinCommunityToolkit icon indicating copy to clipboard operation
XamarinCommunityToolkit copied to clipboard

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

Open sasukevita opened this issue 4 years ago • 4 comments

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);
  1. Execute float service button
  2. Close App
  3. Reopen App from float service button
  4. 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

  • Version with issue: 1.2.0
  • Last known good version: - (First Time Use)
  • IDE: Visual Studio 2019
  • Platform Target Frameworks:
    • Android: 9
  • Android Support Library Version:
  • Nuget Packages: 1.2.0
  • Affected Devices: Android

Workaround

try { await this.DisplayToastAsync(options); } catch {}

sasukevita avatar Aug 05 '21 04:08 sasukevita

Could you please attach a small project to reproduce the issue

VladislavAntonyuk avatar Aug 09 '21 06:08 VladislavAntonyuk

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

jfversluis avatar Aug 09 '21 20:08 jfversluis

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.

VladislavAntonyuk avatar Aug 10 '21 06:08 VladislavAntonyuk

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

ThomasBernardPageUp avatar Jun 21 '22 13:06 ThomasBernardPageUp