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

Calling SetBinding after setting a constant value crashes #17776

Closed
fsdsabel opened this issue Oct 2, 2023 · 4 comments · Fixed by #17796 or #17365
Closed

Calling SetBinding after setting a constant value crashes #17776

fsdsabel opened this issue Oct 2, 2023 · 4 comments · Fixed by #17796 or #17365
Assignees
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! fixed-in-8.0.0-rc.2.9511 Look for this fix in 8.0.0-rc.2.9511 platform/android 🤖 platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Milestone

Comments

@fsdsabel
Copy link

fsdsabel commented Oct 2, 2023

Description

If I set a binding on a control in code behind after a constant value has been set, the application crashes with an ArgumentException: An item with the same key has already been added. Key: Microsoft.Maui.Controls.SetterSpecificity (Parameter 'key')

This is new behavior in .NET 8 as I cannot reproduce this with .NET 7. We use this heavily in our quite large application with many user controls and for us it is almost a blocker for migration to .NET 8. There might be a workaround but it's difficult to spot all the instances this is happening. We are really looking forward to 8 as we are dealing with a lot of bugs in 7 that are really slowing us down.

Steps to Reproduce

  1. Create a File -> New MAUI App
  2. Replace the content of OnCounterClicked in MainPage.xaml.cs with this:
// if CounterBtn already has a binding set on BackgroundColor, this sequence crashes immediately, otherwise it crashes the second time it's called
CounterBtn.BackgroundColor = Colors.Coral;            
CounterBtn.SetBinding(BackgroundColorProperty, new Binding(nameof(BackgroundColor), source: this));
  1. Run the app (verified on Windows)
  2. Click the "Click me" button twice. The second time the app will crash.

Link to public reproduction project repository

No response

Version with bug

8.0.0-rc.1.9171

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.92

Affected platforms

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

Affected platform versions

All

Did you find any workaround?

No. Even clearing the binding or setting the property to null doesn't help.

Relevant log output

No response

@fsdsabel fsdsabel added the t/bug Something isn't working label Oct 2, 2023
@PureWeen PureWeen added the potential-regression This issue described a possible regression on a currently supported version., verification pending label Oct 2, 2023
@PureWeen PureWeen added the area-xaml XAML, CSS, Triggers, Behaviors label Oct 2, 2023
@jsuarezruiz jsuarezruiz added this to the .NET 8 GA milestone Oct 2, 2023
@StephaneDelcroix
Copy link
Contributor

it's probably already fixed, I'll write a test to be 100% sure

@fsdsabel
Copy link
Author

fsdsabel commented Oct 4, 2023

Yes it's fixed in the current nightly. Thanks!

@MauiUIui
Copy link

MauiUIui commented Oct 4, 2023

Yes it's fixed in the current nightly. Thanks!

How did you get the nightly build? Could you please point it out?

@fsdsabel
Copy link
Author

fsdsabel commented Oct 5, 2023

Yes it's fixed in the current nightly. Thanks!

How did you get the nightly build? Could you please point it out?

I used the steps provided here: https://github.com/dotnet/installer/blob/main/README.md

In my case I used the alternative NuGet package source and updated to the latest nightly build in package manager. Make sure to check "Include prerelease". One culprit though: The RC1 build are listet at the top of the list. You have to scroll a bit to find the nightly builds. I didn't see that at first. There are a lot of builds.

github-actions bot pushed a commit that referenced this issue Oct 9, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! label Oct 10, 2023
github-actions bot pushed a commit that referenced this issue Oct 20, 2023
rmarinho pushed a commit that referenced this issue Oct 23, 2023
github-actions bot pushed a commit that referenced this issue Oct 23, 2023
samhouts pushed a commit that referenced this issue Oct 23, 2023
Co-authored-by: Stephane Delcroix <stephane@delcroix.org>
@ghost ghost locked as resolved and limited conversation to collaborators Nov 9, 2023
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.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! fixed-in-8.0.0-rc.2.9511 Look for this fix in 8.0.0-rc.2.9511 platform/android 🤖 platform/windows 🪟 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Projects
None yet
6 participants