Skip to content

[.net 11] Lazy ResourceDictionary factories are resolved during VisualElement resource propagation #35500

Closed

Description

@AdamEssenmacher

Lazy ResourceDictionary values are getting resolved during resource propagation

I noticed a likely oversight in the .NET 11 lazy ResourceDictionary work: some VisualElement resource propagation paths still enumerate resource key/value pairs, which resolves lazy resources even when the resource is never requested.

Repro branch:

https://github.com/AdamEssenmacher/maui/tree/repro/lazyrd-repro

The repro adds two failing tests:

  • AssigningResourcesToElementDoesNotResolveLazyResources
  • ParentSetDoesNotResolveLocalLazyResources

Both fail with:

Expected: 0
Actual:   1

Likely cause

VisualElement.Resources assignment still does:

OnResourcesChanged(value);

and a few parent-resource paths build key sets by enumerating Resources:

foreach (KeyValuePair<string, object> c in Resources)
    innerKeys.Add(c.Key);

Since ResourceDictionary enumeration resolves lazy values, these paths accidentally invoke lazy factories.

Suggested fix

Use key-only paths when only keys are needed:

OnResourcesChangedKeys(value?.Keys);

and:

foreach (string key in Resources.Keys)
    innerKeys.Add(key);

One caveat: the final fix should preserve existing behavior for null-valued resources, since the current key-based resolver path can skip null.

Impact

I ran a quick BenchmarkDotNet comparison against a prototype fix:

Scenario Current net11.0 Prototype fix
Assign 2,000 lazy resources 10.59 ms / 4.32 MB 0.631 ms / 0.65 MB
Assign 5,000 lazy resources 28.66 ms / 10.71 MB 1.89 ms / 1.54 MB
Parent 100 views, 20 lazy/view 27.85 ms / 39.3 MB 17.17 ms / 35.6 MB
Parent 200 views, 20 lazy/view 51.97 ms / 77.8 MB 39.84 ms / 70.5 MB
Parent 200 views, 50 lazy/view 157.61 ms / 177.6 MB 108.98 ms / 159.6 MB

So this looks like it can materially reduce the benefit of lazy resources in larger apps with thousands of resources or pages that materialize lots of views at once.

Activity

  1. added
    t/bug
    on May 18, 2026
  2. TamilarasanSF4853 commented on May 18, 2026

    @TamilarasanSF4853
    Contributor

    This issue has been validated in Visual Studio Code 1.120.0 with the net11 branch. The issue was reproducible.

    Image Image
  3. added
    s/verified
    s/triaged
    area-xaml
    on May 18, 2026
  4. added this to the Backlog milestone on May 19, 2026
  5. added
    partner/syncfusion
    on Aug 6, 2026
  6. added a commit that references this issue on Aug 12, 2026
    be089b0
  7. github-actions commented on Aug 12, 2026

    @github-actions
    Contributor

    Closed by #37257 (merged to net11.0). GitHub only auto-closes for PRs merged to the default branch; this issue was fixed by a PR merged to a non-default branch.

  8. locked and limited conversation to collaborators on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-xamlpartner/syncfusions/triageds/verifiedt/bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions