Skip to content

fix(navigation): only map route types from the resolver's own load context - #3249

Merged
kazo0 merged 6 commits into
mainfrom
dev/sb/3248-route-resolver-alc
Oct 15, 2026
Merged

kazo0 merged 6 commits into
mainfrom
dev/sb/3248-route-resolver-alc

Conversation

@kazo0

@kazo0 kazo0 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #3248

PR Type

  • Bugfix

What is the current behavior?

  • RouteResolverDefault.LoadedTypes builds its by-name type map from AppDomain.CurrentDomain.GetAssemblies(), so it includes types from every AssemblyLoadContext in the process.
  • In a host that loads apps into their own collectible load contexts, the first hot-reload update after a new app loads can reflect over the types of a context that is still unloading, and the process crashes with an AccessViolationException (Hot reload can crash the process when apps run in collectible load contexts #3248).
  • A route can also resolve to another app's type with the same name.

What is the new behavior?

  • The implicit lookup scans the resolver's own load context first, then the default one (skipping default-context assemblies the own context already has, as HotReloadAgent does). The app's own type wins over a same-named type in the default context.
  • In a normal app the resolver lives in the default context, so the scanned assemblies and their order are unchanged.
  • Behaviour change: types in assemblies loaded into some other load context (for example via Assembly.LoadFile) no longer feed the implicit by-name lookup. Explicit ViewMap/RouteMap registrations are unaffected.

Reviewer's guide

  • Start here: src/Uno.Extensions.Navigation.UI/RouteResolverDefault.cs — LoadedTypes and OwnAndDefaultContextAssemblies.
  • CI commits (226c4aec4, 2facced08): no navigation unit test ran in CI. They add Uno.Extensions.Navigation.Tests to the solution and to Uno.Extensions-packageonly.slnf, so the package build's VSTest step picks it up (the existing NavigatorExtensionsTests runs too). The test project references the WinUI navigation project; as a plain SDK project it reads the Uno version from global.json (UnoVersion, which Uno.Sdk projects get from the SDK), so central transitive pinning stays on. It also disables the UNOB0025 runtime-host check: the tests load Navigation types but never start the Uno runtime. (226c4aec4 first turned pinning off; 2facced08 reverts that after it let vulnerable transitive packages through on the Windows restore.)
  • Tests that prove it (f2af9ccde and 5b3fc253a):
    • When_TypeOnlyInOtherLoadContext_Then_NotResolved — a type emitted into a separate collectible context must not resolve; a default-context type still must. Fails on the old code.
    • When_ResolverInOwnLoadContext_Then_OwnTypeWinsOverDefault — a second copy of Navigation.UI in its own context resolves its own SharedNameModel over the default context's. Fails on the old code.
    • When_AssemblyAlsoInOwnLoadContext_Then_DefaultCopyIgnored — when the resolver's context has its own copy of an assembly, the default context's copy is not scanned. Fails if the simple-name filter is removed.
  • Note: the fix commit's body mentions an extended warning; 3c95e826a reverts that, the message is unchanged.
  • Watch for: ToDictionaryDistinct (Uno.Core.Extensions.Collections) keeps the first entry for a key; that is what makes own-context-first win.

Interaction with #3238

The new Android and iOS hot-reload lanes run the navigation hot-reload tests in the app's own process, which is the normal case: the resolver lives in the default load context. There the scanned set is exactly what it was before. AssemblyLoadContext.Default.Assemblies filters the same list that AppDomain.GetAssemblies() returns. On Mono, every assembly is in the default context unless code creates another load context, and hot-reload deltas are applied to the existing assembly without loading a new one. The two PRs touch different files and merge cleanly. This PR stays a draft until #3238 merges, so its CI also runs the new mobile hot-reload lanes.

PR Checklist

  • Tested code with current supported SDKs
  • Unit Tests and/or UI Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Contains NO breaking changes — see the behaviour change above
  • Associated with an issue (GitHub or internal)

Other information

  • Needs a backport to servicing/7.4 after merge (RouteResolverDefault.cs is identical there; the test project's pinning setting may need a look).

🤖 Generated with Claude Code

https://claude.ai/code/session_01MbFsmmtympxmbLYQU2JKGQ

kazo0 and others added 5 commits October 15, 2026 12:37
- Add Uno.Extensions.Navigation.Tests to Uno.Extensions.sln and Uno.Extensions-packageonly.slnf, so the package stage builds it and its VSTest step picks up the assembly
- Reference Uno.Extensions.Navigation.WinUI from the test project, so RouteResolverDefault can be tested directly in a plain test host
- Turn off central transitive pinning in that project: the central Uno.WinUI version is $(UnoVersion), which only Uno.Sdk defines, so pinning dropped Uno.WinUI and the Navigation.WinUI module initializer failed to find Uno.UI
- Prepares the regression tests for #3248

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MbFsmmtympxmbLYQU2JKGQ
…contexts

- When_TypeOnlyInOtherLoadContext_Then_NotResolved: a type loaded only into another collectible AssemblyLoadContext must not resolve by name, while a type in the default context still does
- When_ResolverInOwnLoadContext_Then_OwnTypeWinsOverDefault: a resolver loaded into an app's own context resolves the app's type ahead of a same-named type in the default context, and still sees default-context types
- Both fail on the current code, which scans every assembly in the process (#3248)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MbFsmmtympxmbLYQU2JKGQ
… and default load contexts

- RouteResolverDefault.LoadedTypes scanned every assembly in the process, including other apps' collectible AssemblyLoadContexts; a host that loads apps into their own collectible contexts could crash while reading types from a context that was unloading (#3248)
- Scan the resolver's own load context, then the default one, skipping default assemblies whose simple name the own context already has (same scoping as the hot reload agent); the app's own type now wins over a same-named type in the default context
- In a normal app the own context is the default one, so the scanned set is unchanged; assemblies loaded into a separate context (for example with Assembly.LoadFile) no longer feed the implicit by-name lookup and need an explicit ViewMap/RouteMap
- Log the load context and assembly count at Debug when the type index is built, and say in the unresolved-path warning where implicit lookup searches

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MbFsmmtympxmbLYQU2JKGQ
…resolver's context also has

- When_AssemblyAlsoInOwnLoadContext_Then_DefaultCopyIgnored: an assembly with the same simple name sits in both the default context and the resolver's own context; a type only the default copy defines must not resolve, while the own copy's type does
- Fails if the simple-name filter in OwnAndDefaultContextAssemblies is removed
- Share the own-context resolver setup between the two own-context tests
- Describe the host scenario in neutral terms in the class remarks
- Part of #3248

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MbFsmmtympxmbLYQU2JKGQ
…ontext log

- Restore the original "Could not resolve type for path" warning; it fires on every ordinary suffix miss, so the load-context hint misled
- Name only the default load context in the Debug log when the resolver runs there
- Document where precedence comes from (own context first, first entry kept) and why a default-context assembly the own context also has is skipped
- Part of #3248

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MbFsmmtympxmbLYQU2JKGQ
@kazo0
kazo0 force-pushed the dev/sb/3248-route-resolver-alc branch from 3fcd3ee to 3c95e82 Compare October 15, 2026 16:37
@kazo0
kazo0 marked this pull request as ready for review October 15, 2026 18:30
@kazo0
kazo0 enabled auto-merge October 15, 2026 18:30
- Turning pinning off let restores without package pruning (the Windows package and sample builds) pick System.Net.Http 4.3.0 and System.Text.RegularExpressions 4.3.0, which NuGet audit fails with NU1903
- Keep pinning on and give this plain test host the $(UnoVersion) that Uno.Sdk projects get, read from the Uno.Sdk.Private pin in global.json, so Uno.WinUI is pinned instead of dropped
- Turn off the UNOB0025 runtime-host check here: the tests load navigation types but never start the Uno runtime
- Part of #3248

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MbFsmmtympxmbLYQU2JKGQ
@mergify

mergify Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@kazo0
kazo0 merged commit 9527b28 into main Oct 15, 2026
25 of 26 checks passed
@kazo0
kazo0 deleted the dev/sb/3248-route-resolver-alc branch October 15, 2026 19:36
kazo0 added a commit that referenced this pull request Oct 27, 2026
…te doesn't resolve

- Since #3249, a view in another AssemblyLoadContext no longer resolves by name, but the warning read the same as a typo, and the scope was only logged at Debug
- The "Could not resolve type for path" warning now says which load contexts were searched and that types elsewhere need an explicit ViewMap/RouteMap
- Add Given_RouteResolverDefault in Navigation.UI.Tests: through the resolver itself, a view model loaded only into another load context does not resolve, one in the resolver's own context does, and the warning names the searched contexts; making the index scan every assembly in the process fails it
- Gated to desktop, like the repo's other emitted-assembly tests; no CI lane runs Navigation.UI.Tests today (the desktop lane's RuntimeTestsFilter leaves it out and the skia !_HotReload stage is disabled), so it was run locally on the desktop head
- Part of #3248

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PZQ75nMpDZr9xNdRwacVQN
kazo0 added a commit that referenced this pull request Oct 27, 2026
fix(navigation): follow-ups to #3249 — test host without Navigation.WinUI, case-insensitive name match, docs
agneszitte added a commit that referenced this pull request Nov 3, 2026
…ntext (backport #3249)

- Backport of #3249 to servicing/7.4
- Uno.Extensions.sln: keeps 7.4's Authentication test projects next to the Uno.Extensions.Navigation.Tests entries #3249 adds

Co-Authored-By: Claude Opus 5.5 <[email protected]>
agneszitte added a commit that referenced this pull request Nov 3, 2026
…nUI, case-insensitive name match, docs (backport #3254)

- Backport of #3254 to servicing/7.4, applied without changes

Co-Authored-By: Claude Opus 5.5 <[email protected]>
agneszitte added a commit that referenced this pull request Nov 3, 2026
…6.7-sr3

fix: get servicing/7.4 ready for 6.7 SR3 (backport #3228, #3231, #3235, #3249, #3254, #3259; Uno floor 6.7.65)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hot reload can crash the process when apps run in collectible load contexts

2 participants