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

Binding OnIdiom inside IsVisible causes crash in release mode #16725

Closed
ghost opened this issue Aug 13, 2023 · 11 comments · Fixed by #24594
Closed

Binding OnIdiom inside IsVisible causes crash in release mode #16725

ghost opened this issue Aug 13, 2023 · 11 comments · Fixed by #24594
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.90 fixed-in-9.0.0-rc.2.24503.2 linker issues with objects being trimmed inappropriately (sub: perf) migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@ghost
Copy link

ghost commented Aug 13, 2023

Description

If we use binding to a IsVisible property along with OnIdiom markup extension app crashes in release mode at InitiliazeCompenent(). Works fine on debug mode.

Ex :
<Label Text="im hidden" IsVisible="{OnIdiom Default=false,Phone={Binding EnableLabel}}"/>

Steps to Reproduce

  1. Create a new .net maui project
  2. Add a class MainPageViewModel and define a bindable property "EnableLabel"
  3. Im Mainpage.xaml create a label inside a stacklayout(or any) and bind it like this

<Label Text="im hidden" IsVisible="{OnIdiom Default=false,Phone={Binding EnableLabel}}"/>

4.Set the BindingContext in Mainpage.xaml.cs to MainPageViewModel
5.In MainPageViewModel constructor set EnableLabel to true

Build and deploy

Expected result :
Wee se the label in phone in release mode

Actual result:
App crashes in release mode . Works fine in debug mode

Link to public reproduction project repository

https://github.com/dotnet/maui/files/12414955/16725.zip

Version with bug

7.0.49

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, I was not able test on other platforms

Affected platform versions

Android 13,Ios 16

Did you find any workaround?

Try to assign the IsVisble property in xaml.cs file instead of binding like below

 if(DeviceInfo.Idiom == DeviceIdiom.Phone)
{
    myControl.IsVisible = true;
}

Note* - myControl is x:Name of your control

or if you don't want assign it in xaml.cs bind Isvisible property without Onidiom markup extension and in viewmodel where ever you are assigning the property value use

 if(DeviceInfo.Idiom == DeviceIdiom.Phone)
{
    LabelVisible = true;
}
else
{
  LabelVisible = false;
}

Relevant log output

No response

@ghost ghost added the t/bug Something isn't working label Aug 13, 2023
@drasticactions drasticactions added the s/needs-repro Attach a solution or code which reproduces the issue label Aug 14, 2023
@ghost
Copy link

ghost commented Aug 14, 2023

Hi @the-crow-club. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@drasticactions
Copy link
Contributor

Having a GitHub repo with this code makes it easier for us to quickly debug, verify, and potentially fix the issue against a codebase that you can also test against to verify our changes, as well as use it to create test cases against in the future. I can understand that it can be tedious to do, but it will be helpful.

@samhouts samhouts added area-xaml XAML, CSS, Triggers, Behaviors area/migration 🚚 migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert linker issues with objects being trimmed inappropriately (sub: perf) labels Aug 15, 2023
@ghost
Copy link
Author

ghost commented Aug 20, 2023

@drasticactions Sorry but i cant provide git hub repo due to my limited access to github at my workspace

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Aug 20, 2023
@drasticactions drasticactions added s/needs-repro Attach a solution or code which reproduces the issue and removed s/needs-attention Issue has more information and needs another look labels Aug 20, 2023
@ghost
Copy link

ghost commented Aug 20, 2023

Hi @the-crow-club. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost
Copy link
Author

ghost commented Aug 20, 2023

@XamlTest a bit of help here?

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Aug 20, 2023
@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Aug 23, 2023
@XamlTest
Copy link

XamlTest commented Aug 23, 2023

I can verify this issue on Visual Studio Enterprise 17.8.0 Preview 1.0. Repro on Android 13.0-API33 and iOS .NET 8, not repro on Windows 11 with below Project:
16725.zip

@rmarinho rmarinho removed the s/needs-attention Issue has more information and needs another look label Aug 28, 2023
@rmarinho rmarinho added this to the Backlog milestone Aug 28, 2023
@ghost
Copy link

ghost commented Aug 28, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@hwsmo
Copy link

hwsmo commented Nov 4, 2023

Hi, I can also confirm the bug. It cost me a lot of nerves until I found out that this was the case. Very frustrating :(

@masoltani
Copy link

masoltani commented Mar 4, 2024

Hi, I can also confirm the bug. It cost me a lot of nerves until I found out that this was the case. Very frustrating :(

Hi, I am facing the same issue with .NET 8.

@formerlymisterhenson
Copy link

Facing the same issue - as a workaround I created a converter (which basically does the conditional part mentionend by op)

@StephaneDelcroix
Copy link
Contributor

should be fixed by #24594. writing a test

StephaneDelcroix added a commit that referenced this issue Sep 5, 2024
- fixes #24500
- fixes #16725
@samhouts samhouts modified the milestones: Backlog, .NET 8 SR9 Sep 20, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.90 fixed-in-9.0.0-rc.2.24503.2 linker issues with objects being trimmed inappropriately (sub: perf) migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants