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

[Windows] [RC2] Conditional ToolbarItem Text Display Using OnIdiom Not Working in Release Mode #18697

Closed
malsabi opened this issue Nov 12, 2023 · 14 comments · Fixed by #24594
Closed
Assignees
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.90 fixed-in-9.0.0-rc.2.24503.2 p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@malsabi
Copy link

malsabi commented Nov 12, 2023

Description

When I use Text="{ext:Translate ProfileToolBarText}" without OnIdiom, it works correctly in both Release and Debug modes. However, I intend to display the text on Desktop only, but this setup only works in Debug mode. In Release mode, it incorrectly displays Microsoft.Maui.Controls.Binding

Behavior in Release Mode (incorrect)
Issue1

Behavior in Debug Mode (expected):
Issue2

No exceptions are evident in the output that could indicate the root cause. The issue seems to arise when using OnIdiom.

Steps to Reproduce

  1. Clone the Repository.
  2. Run the application in Release Mode.
  3. You will notice the text is displaying Microsoft.Maui.Controls.Binding.

Link to public reproduction project repository

https://github.com/malsabi/ToolBarItemIssue

Version with bug

8.0.0-rc.2.9511

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows10.0.19041.0

Did you find any workaround?

No I didn't find any workaround.

Relevant log output

No response

@malsabi malsabi added the t/bug Something isn't working label Nov 12, 2023
@jsuarezruiz jsuarezruiz added area-xaml XAML, CSS, Triggers, Behaviors platform/windows 🪟 labels Nov 13, 2023
@jsuarezruiz
Copy link
Contributor

@StephaneDelcroix Thoughts?

@StephaneDelcroix StephaneDelcroix self-assigned this Nov 14, 2023
@StephaneDelcroix
Copy link
Contributor

one path is using SetValue, the other is using SetBinding... I would not have considered this as a bug and only a possible enhancement, but the mismatch between debug and release require a solution

@malsabi malsabi closed this as completed Nov 14, 2023
@malsabi malsabi reopened this Nov 14, 2023
@malsabi
Copy link
Author

malsabi commented Nov 14, 2023

one path is using SetValue, the other is using SetBinding... I would not have considered this as a bug and only a possible enhancement, but the mismatch between debug and release require a solution

Is there any workaround that we can use at the moment ?

@malsabi
Copy link
Author

malsabi commented Nov 19, 2023

@StephaneDelcroix If there's any workaround for this issue please let me know, we are deploying our app on December.

@cgomezm
Copy link

cgomezm commented Nov 30, 2023

@malsabi i have it working like this in case you don't need anything from the binding
public object ProvideValue(IServiceProvider serviceProvider)
{
return Translator.Instance[Key];
}

Just return the string value and it will work in both debug/release

@malsabi
Copy link
Author

malsabi commented Dec 2, 2023

@cgomezm
Hello thanks for replying.
I tried the approach but it didn't work on release mode it kept on crashing, here is how I tried it:
Maybe you could create a PR to the same repo I provided earlier.

namespace ToolBarItemIssue.Common.Extensions
{
   [ContentProperty(nameof(Name))]
   public class TranslateExtension : IMarkupExtension<BindingBase>
   {
       public string? Name { get; set; }

       public BindingBase ProvideValue(IServiceProvider serviceProvider)
       {
           throw new NotImplementedException();
       }

       object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
       {
           if (string.IsNullOrEmpty(Name))
               return "N/A";
           return LocalizationResourceManager.Instance[Name];
       }
   }
}

@cgomezm
Copy link

cgomezm commented Dec 4, 2023

@malsabi I moved away from returning the binding and just return the string value.

[ContentProperty(nameof(Key))]
internal class TranslateExtension : IMarkupExtension
{
    public string Key { get; set; }

    public object ProvideValue(IServiceProvider serviceProvider)
    {
        return Translator.Instance[Key];
    }
} 

@malsabi
Copy link
Author

malsabi commented Dec 4, 2023

@cgomezm
I can confirm your code works on Release / Debug mode however when I try to change the language in runtime it does not work.
I tried using the following snippet:

if (AppResources.Culture.TwoLetterISOLanguageName.Equals("en"))
{
    LocalizationResourceManager.Instance.SetCulture(new CultureInfo("ar"));
}
else
{
    LocalizationResourceManager.Instance.SetCulture(new CultureInfo("en"));
}

@cgomezm
Copy link

cgomezm commented Dec 5, 2023

@malsabi yeah, that could be a downside as is the value being returned instead of the binding. Maybe dotnet team has made some progress on their investigation of this.

@malsabi
Copy link
Author

malsabi commented Dec 5, 2023

@jsuarezruiz any thoughts or progress about this issue ?

@mikeparker104 mikeparker104 added partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with platform/android 🤖 labels Dec 20, 2023
@samhouts samhouts added the p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint label Dec 21, 2023
@Redth Redth added this to the .NET 8 SR3 milestone Jan 10, 2024
@PureWeen PureWeen moved this from Todo to To Move in MAUI SDK Ongoing Feb 28, 2024
@PureWeen PureWeen moved this from To Move to In Progress in MAUI SDK Ongoing Mar 5, 2024
@PureWeen PureWeen modified the milestones: .NET 8 SR3, .NET 8 SR4 Mar 5, 2024
@PureWeen PureWeen modified the milestones: .NET 8 SR4, .NET 8 SR5 Apr 9, 2024
@RoiChen001
Copy link

Can repro this issue at Windows platform on the latest 17.10.0 Preview 3(8.0.7&8.0.20).

@RoiChen001 RoiChen001 added the s/verified Verified / Reproducible Issue ready for Engineering Triage label Apr 12, 2024
@PureWeen PureWeen added this to the .NET 8 SR6 milestone Apr 25, 2024
@PureWeen PureWeen modified the milestones: .NET 8 SR6, .NET 8 SR7 Jun 3, 2024
StephaneDelcroix added a commit that referenced this issue Jun 11, 2024
Compile OnIdiom markup extension. Doing that we can infer the type of
the ProvidedValue instead of using Object

- fixes #18697
StephaneDelcroix added a commit that referenced this issue Jun 11, 2024
Compile OnIdiom markup extension. Doing that we can infer the type of
the ProvidedValue instead of using Object

- fixes #18697
@StephaneDelcroix
Copy link
Contributor

We can not fix this, in either way: it's not possible (using a reasonable effort) to make it succeed (in all cases) when XamlC is on, and it's not possible to have it fail when XamlC is off

one way would be to deprecate OnIdiom in favour of OnIdiom (oh, well, it used to be that way)

@StephaneDelcroix
Copy link
Contributor

found a solution, finally

StephaneDelcroix added a commit that referenced this issue Jun 26, 2024
align debug behavior with compiled one. OnIdiom doesn't tell the
compiler the type returned, so it can't Setbinding

- fixes #18697
- fixes #22877
@malsabi
Copy link
Author

malsabi commented Jun 26, 2024

found a solution, finally

Can you tell us what was the solution ? Is there any changes we need to know about ?

@PureWeen PureWeen modified the milestones: .NET 8 SR7, .NET 8 SR8 Jul 2, 2024
StephaneDelcroix added a commit that referenced this issue Jul 18, 2024
align debug behavior with compiled one. OnIdiom doesn't tell the
compiler the type returned, so it can't Setbinding

- fixes #18697
- fixes #22877
@PureWeen PureWeen modified the milestones: .NET 8 SR8, .NET 8 SR9 Jul 30, 2024
github-actions bot pushed a commit that referenced this issue Aug 9, 2024
align debug behavior with compiled one. OnIdiom doesn't tell the
compiler the type returned, so it can't Setbinding

- fixes #18697
- fixes #22877
@PureWeen PureWeen moved this from In Progress to Ready To Review in MAUI SDK Ongoing Aug 12, 2024
StephaneDelcroix added a commit that referenced this issue Sep 4, 2024
- fixes #19388
- fixes #18697
- closes #23798
- closes #23272

and some others
StephaneDelcroix added a commit that referenced this issue Sep 4, 2024
- fixes #19388
- fixes #18697
- fixes #22877
- closes #23798
- closes #23272

and some others
@PureWeen PureWeen moved this from In Progress to Ready To Review in MAUI SDK Ongoing Sep 10, 2024
@github-project-automation github-project-automation bot moved this from Ready To Review to Done in MAUI SDK Ongoing Sep 10, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 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 p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Status: Done
9 participants