Skip to content

ResourceDictionary.ContainsKey method never returns trueΒ #13268

Closed as not planned

Description

@tjbarrott

Description

ResourceDictionary.ContainsKey method never returns true

Steps to Reproduce

var mergedDictionaries = Application.Current.Resources.MergedDictionaries;
foreach(var dictionary in mergedDictionaries)
{
    foreach(var key in dictionary.Keys)
    {
        bool containsKey = dictionary.ContainsKey(key);
    }
}

containsKey is always false. I originally just tried dictionary.ContainsKey("myKey") and it always returned false, which led me to use the above code which should always return true.

Link to public reproduction project repository

https://github.com/tjbarrott/MergedDictionariesTest

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

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

Affected platform versions

c# problem

Did you find any workaround?

Yes. run through the keys in foreach loop and see if the key equals the string

Relevant log output

No response

Activity

  1. added
    t/bug
    on Feb 11, 2023
  2. added
    area-xaml
    s/needs-repro
    on Feb 13, 2023
  3. tjbarrott commented on Feb 14, 2023

    @tjbarrott
    Author

    https://github.com/tjbarrott/MergedDictionariesTest

    I put the code in MainPage.xaml.cs

    That repo uses .net 6. I also tried it in .net 7 with the same result.

  4. ghost added
    s/needs-attention
    on Feb 14, 2023
  5. ghost removed
    s/needs-repro
    on Feb 14, 2023
  6. removed
    s/needs-attention
    on Feb 14, 2023
  7. added this to the Backlog milestone on Feb 14, 2023
  8. hartez commented on Feb 14, 2023

    @hartez
    Contributor

    This is happening because ResourceDictionary's ContainsKey method only checks the inner dictionary, and ignores the merged dictionaries: https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/ResourceDictionary.cs#L179

    The method needs to be updated, and the unit tests need to be updated to test for this.

  9. self-assigned this
    on Feb 15, 2023
  10. moved this from Todo to In Progress in MAUI SDK Ongoingon Feb 17, 2023
  11. 9 remaining items

  12. Ghostbird commented on Mar 16, 2023

    @Ghostbird
    Contributor

    @Cybrosys I guess I did something wrong when first trying your extension method. It's working now.

  13. Cybrosys commented on Mar 16, 2023

    @Cybrosys

    @Cybrosys I guess I did something wrong when first trying your extension method. It's working now.

    It was a quickly cobbled together method that achieved what I was trying to do when testing something. I wouldn't be surprised if there are some quirks or odd behaviors with it due to how ResourceDictionary behaves.

  14. jfversluis commented on Apr 6, 2023

    @jfversluis
    Member

    Looking at the discussion and linked, closed PR, I think this is a variation of: #11214 (comment)

    As such, closing this for now.

  15. ghost locked as resolved and limited conversation to collaborators on May 6, 2023
  16. added
    s/not-a-bug
    on May 12, 2023
  17. modified the milestones: Backlog, .NET 8 on May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-xamlplatform/androidplatform/iosplatform/macosplatform/windowss/not-a-bugt/bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions