Repository navigation
fix(devserver): load add-ins into a single ALC for cross-add-in type sharing - #23308
Merged
Merged
Conversation
…sharing PR #23287 isolated add-in loading into a custom AssemblyLoadContext to fix three cross-major-version FileNotFoundException scenarios (Kiota, Mcp, ModelContextProtocol). The isolation worked for those scenarios but introduced a structural fragility: add-ins registering their types in the host's IServiceCollection (which lives in the default ALC) cannot reliably be resolved by other add-ins that reference the same types — the cross-ALC Type identity mismatch surfaces as either FileNotFoundException during JIT inspection of a constructor signature or InvalidOperationException from DI ("Unable to resolve service for type ..."). The bug is visible to end users as the Uno Platform Studio overlay never finishing initialization (issue #23304). Three ALCs coexisted in the host before this change: Default (host + IServiceCollection), AddInLoadContext (the --addins payload), and the per-applicationId ALC built by RemoteControlServer.GetAssemblyLoadContext for client-sent processors. Sharing Type identities across these boundaries is structurally impossible to do reliably — no amount of probing inside any single ALC can fix it. Fix: load every add-in via Assembly.LoadFrom directly into the default ALC. All add-in types — including private contract assemblies physically co-located with one add-in but absent from every add-in's deps.json — observe a single Type identity, which is what DI needs to match service registrations with constructor parameters. The three cross-major-version scenarios that PR #23287 originally fixed remain handled by the Default.Resolving handler in HostAssemblyResolution.Install + TryBridgeBySimpleName, which existed independently of the ALC isolation and stays in place. The runtime's LoadFromResolveHandler also probes the loaded-from directories of every Assembly.LoadFrom'd assembly, so contract DLLs co-located with one add-in are discoverable from another. Diagnostic enrichments — both layers route through stdout/stderr so the operator sees them in the host log: * Proactive: AssemblyHelper.Load now walks each loaded add-in's AssemblyRef table and warns on version/PKT mismatches against the host's loaded set. The warning names the add-in, the misaligned reference, the runtime consequence, and the two remediation paths (align the package version, or load the conflicting dependency in a private AssemblyLoadContext owned by the add-in). Verbose mode via env-var UNO_DEVSERVER_VERBOSE_ADDIN_REFS=1. * Reactive: TryBridgeBySimpleName logs info-level when a successful bridge involves a version substitution, and warning-level when it returns null — naming the same-simple-name variants currently loaded so the operator has a concrete starting point. PKT match in TryBridgeBySimpleName is now asymmetric: a signed request (non-empty PublicKeyToken) requires a matching loaded PKT, while unsigned requests skip the check entirely. This is identity validation, not an allow-list — no static trusted PKT table. The previous symmetric "unsigned request refuses strong-named loaded" rule was over-conservative and is removed; the unused s_trustedPkts allow-list + IsTrustedPkt warning are gone with it. Other simplifications: the UNO_DEVSERVER_DISABLE_ADDIN_ALC kill switch is removed (no ALC isolation to disable any longer). The Given_AddInLoadContext and Given_AssemblyHelper unit tests are gone (their subjects no longer exist). Tests: * New cross-add-in regression DevServer_ShouldResolveSharedContractAcrossAddIns_WhenContractOnlyInProviderDirectory spins up a real DevServer host with two fixture add-ins (provider shipping Uno.Licensing.TestContracts.dll, consumer not), asserts the consumer's IHostedService receives the DI-injected contract — verified RED on master and GREEN after the fix. * Asymmetric PKT match is locked in by three new TryBridgeBySimpleName tests covering signed-mismatch (refused), signed-match (bridged), and unsigned-request (bridged). * The existing AddInWithCrossMajorVersionRefs integration test is preserved as non-regression for the three scenarios PR #23287 fixed. CI: a new Linux-only stage (devserver_tests_linux) runs the DevServer test project independently — fast PR feedback for add-in resolution regressions, no dependency on the heavier unit_tests stage. The existing Windows unit_tests stage continues to include the same tests via Uno.UI-UnitTests-only.slnf (with the new fixtures added). Fixes #23304.
…uires explicit option)
Adds Uno.Sdk.AddInVersionValidation.Tests — a regression gate that scans every
DevServer add-in declared in src/Uno.Sdk/packages.json (Uno.Settings.DevServer,
Uno.UI.HotDesign, Uno.UI.App.Mcp) for cross-package AssemblyRef version
mismatches. The test reads the manifest, locates each add-in's restored
NuGet content via the GeneratePathProperty-emitted assembly metadata, walks
their runtime DLLs' AssemblyRef tables via System.Reflection.Metadata
(no assembly loads), and asserts that any simple name referenced by more
than one add-in is referenced at a single version.
When two or more add-ins reference the same simple name with different
versions, the test fails with a structured report:
• the conflicting simple name
• each (version, source-package) pair
• the runtime consequence (FileNotFoundException / TypeLoadException /
'Unable to resolve service')
• the two remediation paths (align the package version, or load the
conflicting dependency in a private AssemblyLoadContext)
• the path to packages.json as the manifest source of truth
The test is intentionally RED whenever the manifest references add-ins with
misaligned dependencies — that is the entire point: PR CI exposes the
misalignment so the add-in maintainers fix it before the SDK ships. Verified
RED locally against the current packages.json (Uno.Settings.DevServer
1.8.0-dev.42, Uno.UI.HotDesign 1.19.0-dev.325, Uno.UI.App.Mcp 1.2.0-dev.41):
conflicts on System.Net.Http, Tmds.DBus.Protocol, Uno.DevTools.Telemetry,
System.Xml.XPath.XDocument and others — exactly the kind of misalignment
that produces the runtime failures the host-side single-ALC fix mitigates
but cannot fully cure.
CI integration:
• Added to src/Uno.UI-UnitTests-only.slnf so the Windows unit-tests stage
picks it up alongside the other unit tests.
• Added to the dedicated devserver_tests_linux stage in
build/ci/tests/.azure-devops-tests-devserver-linux.yml so PR authors see
the misalignment report on Linux (fast / cheap agent class) before the
heavier stages run.
The csproj's PackageReference versions for the three add-ins must match
packages.json — the test verifies this and fails fast on drift, making the
sync requirement self-enforcing.
The build at /buildId=213964 failed because the previous shape of this CI
stage borrowed too much from the heavier stages (NBGV cache, gitversion
template, multiple .NET SDK installs, an additional DevServer integration
test run) — none of which is required for what this stage actually does:
restore three NuGet packages and walk their static AssemblyRef tables.
Reduces the stage to:
- full git clone (Directory.Build.props references NBGV-set properties;
a deep clone avoids restore-time surprises without paying for the
full NBGV task)
- single .NET SDK install via the existing dotnet-install template
(pinned net10 SDK from build/ci/net10/_global.json — enough because
the test targets $(NetCurrent) and only inspects static metadata)
- one `dotnet test --project` invocation
- publish the TRX
The dedicated DevServer host-side integration tests already run on the
Windows unit_tests stage via Uno.UI-UnitTests-only.slnf — no need to
duplicate them here.
Also fixes the missing `--project` flag the new MSTest SDK 4.x requires
(verified locally — the command line in this YAML is exactly the one I
ran from a clean `bin/`/`obj/` state and got the expected RED result).
…d-graph walk
The first iteration scanned every DLL in each add-in's tools/* + lib/* and compared
AssemblyRef tables flatly. That model overcounts: it includes client-side DLLs in
lib/net9.0/ that the DevServer host never loads (MEA v9.8 from HotDesign was a
false positive of this kind), and it ignores intra-add-in forward rolls (Settings
internally referencing SkiaSharp v2.88 in one DLL and v3.119 in another is not a
conflict — the v3.119 DLL it ships is what gets loaded, and the v2.88 ref forward-
rolls cleanly).
The new model walks the actual runtime load graph instead:
1. The host's effective TPA is computed from the .NET shared frameworks
(Microsoft.NETCore.App + Microsoft.AspNetCore.App per the host's runtimeconfig.json)
plus the bundled host deps under tools/rc/host/net10.0/.
2. For each add-in, the BFS root is the primary server DLL declared via the
tools/devserver/*.Server.dll or tools/<tfm>/server/*.Server.dll convention.
3. At every visited DLL, each AssemblyRef is resolved:
host TPA hit → forward-roll OK (don't walk into host DLLs)
host TPA hit, low ver → bridge would refuse; check loadable dir for bundled
copy. If found → case 1 latent (works via
LoadFromResolveHandler, pollutes Default ALC).
If not → case 1 fatal (guaranteed FNFE).
no host hit, bundled → enqueue the bundled DLL, record this add-in's
contribution for cross-add-in comparison.
no host hit, unbundled → record as unresolved (potential case 2 trigger
or surprise FNFE at runtime).
4. Cross-add-in case 2 = same simple name absent from host TPA, contributed at
different versions by two or more add-ins (their LoadFromResolveHandler-
reachable bundles or unresolved demands).
The report distinguishes:
- Case 1 fatal: guaranteed FileNotFoundException at runtime (the kind of bug
PR #23287 documented — host version lower than what an add-in needs, with
no bundled fallback). Currently shows the ModelContextProtocol family for
Uno.UI.App.Mcp.
- Case 1 latent: works today through LoadFromResolveHandler, but Default ALC
ends up carrying two versions of the same simple name. Cross-component code
that tries to mix them gets TypeLoadException. Currently shows
Microsoft.IO.RecyclableMemoryStream (Settings) and Uno.DevTools.Telemetry
(HotDesign).
- Case 2: load-order non-determinism. Empty under the current manifest.
Also adds Uno.WinUI.DevServer to the test's PackageReference set so the host's
runtime payload is restored and walked alongside the three add-ins.
…ly-built host Two changes that remove all manual sync requirements from the alignment test: 1. Add-in PackageReferences are now emitted at restore time by an inline RoslynCodeTaskFactory task that reads each version directly from src/Uno.Sdk/packages.json (the same manifest Uno.Sdk.Private itself consumes). No more hardcoded version pins in the test csproj, no separate sync gate in the test code. The previous flow required hand-editing the csproj whenever packages.json moved — bumps drifted, false positives followed. 2. The DevServer host is now resolved via ProjectReference to Uno.UI.RemoteControl.Host.csproj instead of a fixed Uno.WinUI.DevServer NuGet package. The test always validates the host BUILT BY THIS BRANCH, which catches misalignments against the host actually being shipped — and never against a stale published version. The previous pinned NuGet (6.6.0-dev.527) produced a spectacular false positive: it reported a "guaranteed FNFE" for ModelContextProtocol v0.3 vs v1.1, but every host release from 6.6.0-dev.938 onwards already ships MCP v1.1 in lock-step with Uno.UI.App.Mcp. The fixed pin had drifted off the real shipping host. BuildHostTpa simplified to scan a single directory (the host bin output) instead of a NuGet-package subpath. The .NET shared-framework discovery (Microsoft.NETCore.App + Microsoft.AspNetCore.App via the runtimeconfig.json sibling lookup) stays the same. Result against the current manifest + locally-built host: 0 guaranteed runtime-blocking conflicts, 2 latent ones (Microsoft.IO.RecyclableMemoryStream host v2.3.2 vs Settings v3.0; Uno.DevTools.Telemetry host v1.1.1 vs HotDesign v1.2.1). Both add-ins ship the higher version in their loadable directory so the LoadFromResolveHandler keeps them working today, but Default ALC ends up with two versions of the same simple name — worth aligning to remove the duplication.
MSTest.Sdk emits OutputType=Exe which produces a native apphost wrapper on Linux. The build fails with MSB3024 when the destination path of the renamed apphost collides with an existing folder. The test runs through dotnet test against the DLL, so the apphost is unused — disable it. Also drop the explicit return statements in the RoslynCodeTaskFactory fragment: the factory appends 'return !Log.HasLoggedErrors;' after the fragment, so an explicit final 'return true;' becomes unreachable (CS0162).
Walk the host's primary executable's transitive AssemblyRef table once at test startup and index simpleName → [host DLLs that reference it]. Append the result as 'referenced by <DLL>, <DLL>' to the 'host loaded' line of each Case 1 (fatal / latent) entry so the operator sees immediately which host project to bump the NuGet ref in. The walk uses the same ReadAssemblyRefs() metadata reader the test already uses for add-in DLLs, not NuGet's *.deps.json package graph. That keeps the attribution honest: the binder's strict-version-match runs against AssemblyVersion (the AssemblyRef table) rather than NuGet PackageVersion.
… 1.2.1 Aligns the host bundled versions with what Uno.Settings.DevServer (RecyclableMemoryStream 3.0.0.0) and Uno.UI.HotDesign (Uno.DevTools.Telemetry 1.2.1.0) compile against. Resolves the two Case 1 latent conflicts reported by addin_version_alignment, turning that CI stage green.
Contributor
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23308/wasm-skia-net9/index.html |
Uno.UI-UnitTests-only.slnf referenced five projects that were absent from the main solution file, causing MSB4025 on the Windows unit-tests stage: - Uno.Sdk.AddInVersionValidation.Tests - Uno.UI.RemoteControl.DevServer.Tests/Fixtures/Uno.Licensing.TestContracts - Uno.UI.RemoteControl.DevServer.Tests/Fixtures/AddInWithSharedContractProvider - Uno.UI.RemoteControl.DevServer.Tests/Fixtures/AddInWithSharedContractConsumer
agneszitte
requested review from
MartinZikmund,
ajpinedam,
dr1rrb,
jeromelaban and
nickrandolph
May 22, 2026 14:26
carldebilly
enabled auto-merge
May 22, 2026 14:34
Merged
2 of 5 tasks
dr1rrb
pushed a commit
that referenced
this pull request
Jul 3, 2026
fix(devserver): load add-ins into a single ALC for cross-add-in type sharing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#23287 isolated DevServer add-in loading into a custom
AssemblyLoadContextto fix three cross-major-versionFileNotFoundExceptionscenarios (Kiota,Mcp,ModelContextProtocol). The isolation worked for those scenarios but introduced a structural fragility: add-ins registering their types in the host'sIServiceCollection(which lives in the default ALC) cannot reliably be resolved by other add-ins that reference the same types. The cross-ALCTypeidentity mismatch surfaces as eitherFileNotFoundExceptionduring JIT inspection of a constructor signature orInvalidOperationExceptionfrom DI ("Unable to resolve service for type ..."). End users see this as the Uno Platform Studio overlay never finishing initialization.Three
AssemblyLoadContexts coexisted in the host before this change:Default(host +IServiceCollection),AddInLoadContext(the--addinspayload), and the per-applicationId ALC built byRemoteControlServer.GetAssemblyLoadContextfor client-sent processors. SharingTypeidentities across these boundaries is structurally impossible to do reliably — no amount of probing inside any single ALC can fix it. The earlier attempt that built a file-system probe insideAddInLoadContext.Loadis documented in #23306.Fixes #23304.
Approach
Load every add-in via
Assembly.LoadFromdirectly into the default ALC. All add-in types — including private contract assemblies physically co-located with one add-in but absent from every add-in'sdeps.json— observe a singleTypeidentity, which is what DI needs to match service registrations with constructor parameters.The three cross-major-version scenarios from #23287 remain handled by the existing
Default.Resolvinghandler inHostAssemblyResolution.Install+TryBridgeBySimpleName, which existed independently of the ALC isolation and stays in place. The runtime'sLoadFromResolveHandleralso probes the loaded-from directories of everyAssembly.LoadFrom'd assembly, so contract DLLs co-located with one add-in are discoverable from another at runtime.Diagnostics
Both layers route through stdout / stderr so the operator sees them in the host log:
AssemblyHelper.Loadwalks each loaded add-in'sAssemblyReftable and warns on version / PKT mismatches against the host's loaded set. The warning names the add-in, the misaligned reference, the runtime consequence, and the two remediation paths — (1) align the package version with the host's, or (2) load the conflicting dependency inside a privateAssemblyLoadContextowned by the add-in. Verbose mode via env-varUNO_DEVSERVER_VERBOSE_ADDIN_REFS=1.TryBridgeBySimpleName: info-level message on a successful bridge with version mismatch; warning-level message on anullreturn that lists the same-simple-name variants currently loaded — a concrete starting point for diagnosis.Asymmetric PKT match
TryBridgeBySimpleNameenforces aPublicKeyTokenmatch only when the request carries a non-empty PKT (signed frameworkAssemblyRefs likeSystem.Text.Json). Unsigned requests (typical for add-in contracts) skip the check. Identity validation, not an allow-list. The previous symmetric "unsigned request refuses strong-named loaded" rule was over-conservative and is removed; the unuseds_trustedPktsallow-list +IsTrustedPktwarning are gone with it.Removed
AddInLoadContextclass and its accompanying unit tests (the structural isolation we are reverting).UNO_DEVSERVER_DISABLE_ADDIN_ALCkill switch (no isolation to disable any longer).Alignment validation
src/Uno.Sdk.AddInVersionValidation.Testsgates every PR against version misalignments between the add-ins listed insrc/Uno.Sdk/packages.jsonand the locally-built host. It walks the transitiveAssemblyRefgraph of each add-in's primary DLL and classifies conflicts into:FileNotFoundExceptionat runtime.LoadFromResolveHandlerloads a side-by-side copy into Default ALC. Works, but fragile (load-order-dependent, two major versions coexist).The failure report names the conflicting assembly, the version the host loads, the version each add-in needs, and — for Case 1 — the host DLL(s) that actually reference it (derived from the host's own
AssemblyRefgraph), so the author knows which project's NuGet dependency to bump.The test is intentionally RED for two current latent misalignments and will turn GREEN once those packages align with the host's bundled versions. It runs in the
addin_version_alignmentCI stage.CI
Two CI stages gate the add-in resolution story:
devserver_tests_linux(Linux-only): fast feedback onUno.UI.RemoteControl.DevServer.Tests— add-in resolution unit tests including theAddInWithCrossMajorVersionRefsintegration fixture.addin_version_alignment(Linux-only, intentionally RED): runsUno.Sdk.AddInVersionValidation.Testsagainst the locally-built host and the currentpackages.jsonadd-in versions. Fails until the two latent misalignments are resolved in a follow-up package bump.The existing Windows
unit_testsstage continues to include the DevServer tests viaUno.UI-UnitTests-only.slnf.