Repository navigation
fix(devserver): cross-add-in type sharing via file-system probe in AddInLoadContext - #23306
carldebilly wants to merge 4 commits into
Conversation
…s-add-in type sharing PR #23287 moved add-in loading into a shared AddInLoadContext. Side effect: unsigned contract assemblies (e.g. Uno.Licensing.Sdk.Contracts) that are present in one add-in's directory but absent from other add-ins' deps.json could not be resolved across the ALC boundary, causing: - FileNotFoundException when McpServerProcessor's ctor inspects ILicensingService (Uno.Licensing.Sdk.Contracts not found) - InvalidOperationException: Unable to resolve service for type ILicensingService in HotDesignSourceProcessor (type identity broken) Fix: before building AddInLoadContext, AssemblyHelper.Load now calls EagerLoadFromDirectory for each add-in directory using the new AddInSharedAssemblyPatterns glob ("Uno.Licensing.*.dll"). This loads the contracts DLL into Default ALC, where TryBridgeBySimpleName (step 1 of AddInLoadContext.Load) serves it to all add-ins with a single Type identity. Also removes the misleading s_trustedPkts / IsTrustedPkt PKT warning in EagerLoadFromDirectory — the warning fired for System.Reactive and Microsoft.Extensions.AI.Abstractions, appearing as [ERROR] in VS even though bridging still worked correctly via the symmetric PKT policy in TryBridgeBySimpleName. Tests: new unit tests for the patterns parameter and constants; new cross-add-in type sharing integration test with three fixture projects (Uno.Licensing.TestContracts, AddInWithSharedContractProvider, AddInWithSharedContractConsumer) that reproduce the exact failure scenario (contracts DLL only in provider's directory, absent from consumer's deps.json) and verify the sentinel is written after the fix. Fixes #23304
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23306/wasm-skia-net9/index.html |
…e-system probe
The previous fix pre-loaded `Uno.Licensing.*.dll` from each add-in directory
into Default ALC via a hardcoded glob list (`AddInSharedAssemblyPatterns`).
That couples the generic DevServer host to specific Uno Platform product
names and grows every time a new contract assembly hits the same packaging
quirk. Replace the white-list with a probe that has zero knowledge of which
add-ins are loaded and requires no changes to the currently-published
add-in packages.
Root cause precisely: when a contract DLL is physically present in one
add-in's directory but absent from every add-in's deps.json, steps 1-3 of
`AddInLoadContext.Load` all return null because
`AssemblyDependencyResolver` only consults deps.json — it does not probe
the file system.
Fix: add a fourth resolution step inside `AddInLoadContext.Load` that scans
each registered add-in directory for a matching `{simpleName}.dll` and
loads it via `LoadFromAssemblyPath`. The DLL ends up in the shared add-in
ALC, so every add-in sees the same Type identity and DI resolves cleanly.
This mirrors the implicit probing `Assembly.LoadFrom` performed before
PR #23287 introduced ALC isolation.
Also drop unused machinery:
- Remove `AddInSharedAssemblyPatterns` constant and its companion eager-load
loop in `AssemblyHelper.Load`.
- Drop the `patterns` parameter from `EagerLoadFromDirectory`. The default
host-directory eager-load (`System.*` / `Microsoft.Extensions.*`) remains
unchanged — it is what keeps the cross-major-version scenarios from
PR #23287 working.
- Promote `DefaultEagerLoadPatterns` to `ImmutableArray<string>`.
- Strip the PKT symmetry check from `TryBridgeBySimpleName` and from step 2
of `AddInLoadContext.Load`. Add-ins and contract DLLs are unsigned in
practice; the guard never triggered. Dynamic-skip and version-downgrade
guards stay.
- Replace duplicate kill-switch read in `Install()` with the existing
`IsKillSwitchActive` property.
- Rename `_contract` primary-ctor parameter to `contract` in the consumer
fixture.
Tests:
- New `Given_AddInLoadContext` step-4 tests (red->green TDD): file-system
probe finds DLLs absent from every deps.json, probes every registered
add-in directory (not only the first), and returns null/throws cleanly
when nothing matches.
- Drop the `AddInSharedAssemblyPatterns_*` constant tests and the custom
`patterns` parameter tests.
- Drop `TryBridgeBySimpleName_RejectsStrongNamedLoaded_WhenRequestedIsUnsigned`.
- `DevServer_ShouldResolveSharedContractAcrossAddIns_WhenContractOnlyInProviderDirectory`:
switch `--addins` arg to semicolon-separated paths (host parses a single
string, two space-separated tokens silently dropped the consumer),
and assert the sentinel's AssemblyQualifiedName references the shared
contracts assembly to prove single Type identity end-to-end.
… ordered probe map, error isolation Addresses the review-panel findings on the cross-add-in type-sharing fix: - **Ordered probe map (H2)**: replace `string[] _addInDirectories` derived from a `HashSet<string>` with a `Dictionary<string,string>` (simple name → full path) built once at construction. The dictionary is populated in caller-supplied registration order so "first add-in wins" when two directories ship the same simple name — `HashSet` enumeration order was unspecified and could flip silently across runs. - **Version-downgrade guard (H1)**: step 4 now reads `AssemblyName.GetAssemblyName` on the candidate before loading and refuses a strictly-lower version than requested. Mirrors the symmetric guard in steps 1 and 2; prevents an older co-located DLL from silently satisfying a newer AssemblyRef and turning into `MissingMethodException` later. - **Per-candidate load failure isolation (M1)**: wrap `LoadFromAssemblyPath` in the same `FileNotFoundException`/`FileLoadException`/`BadImageFormatException` catch as step 2. A malformed candidate now returns null (clean FNFE at the call site) instead of bubbling the raw `BadImageFormatException` and aborting the resolution chain. - **Path-traversal guard**: reject `AssemblyName.Name` values containing path separators. The `AssemblyName(string)` constructor already validates this, but the public `Name` setter does not — so the guard is reachable through metadata-free construction and worth exercising. - **Step 4 breadcrumbs (M3)**: log to stderr on probe hit (with resolved path) and on per-candidate load failure, so an operator can tell which add-in directory satisfied a cross-add-in contract resolve and distinguish "no candidate" from "had a candidate but failed to load". `ILoggerFactory` is unavailable at this layer; the stderr fallback matches the existing `EagerLoadFromDirectory` and ctor-failure breadcrumbs. - **O(1) lookup (M5)**: the dictionary snapshot also removes the per-miss `File.Exists × N` directory scan. Hot reflection paths that resolve missing assemblies repeatedly now hit a single hash lookup. - **Stale fixture XML comments (M4)**: rewrite the `AddInWithSharedContract*` csproj documentation. Both files still described the superseded white-list mechanism (`Uno.Licensing.*.dll` eager-load into Default ALC) and the inaccurate "no .deps.json produced" claim. Replaced with the step-4 file-system probe semantics that the fixtures actually exercise. - **Strengthened test assertions**: new `Load_StoresProbedAssemblyInAddInLoadContext_NotInDefault` uses `AssemblyLoadContext.GetLoadContext` to lock in that the probed assembly stays inside the add-in ALC (catches a future regression that loaded into Default and broke isolation). New tests for the version-downgrade refusal, path-traversal rejection, and load-failure isolation cover the new guards TDD-style (red → green).
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23306/wasm-skia-net9/index.html |
…eName and AddInLoadContext step 2
The earlier removal of the PKT check was over-aggressive. The argument
("add-ins are unsigned in practice") only holds for cross-add-in contract
assemblies (Uno.Licensing.Sdk.Contracts and friends) — but the bridge
also serves strong-named framework assemblies whose AssemblyRefs from
compiled add-ins do carry a PublicKeyToken (System.Text.Json, Kiota's
net8 ref to System.Text.Encodings.Web 8.0.0.0, etc.). For those, a
same-name candidate with a different (or absent) PKT must not silently
substitute the wrong identity.
Reintroduce a PKT match — not an allow-list — gated on the request side:
- If the request carries a non-empty PublicKeyToken, the loaded
candidate's PKT must match (signed identity validation).
- If the request is unsigned, skip the PKT check entirely so
cross-add-in contract loading (the file-system-probe scenario) is
unaffected.
The change is symmetric across the two call sites:
- `HostAssemblyResolution.TryBridgeBySimpleName` (step 1 of
`AddInLoadContext.Load` and the `Default.Resolving` handler).
- `AddInLoadContext.Load` step 2 (host TPA lookup): the assembly
returned by `Default.LoadFromAssemblyName` is now PKT-validated
against the request before being handed back.
No static `s_trustedPkts` allow-list is reintroduced. The previous
`IsTrustedPkt` logic was a different concern (warn-on-eager-load) and
not what defended bridging.
Test updates:
- New `TryBridgeBySimpleName_RefusesBridge_WhenSignedRequestPktDoesNotMatchLoaded`
(red-then-green) flips a byte of the real PKT and verifies the
bridge refuses the swap.
- New `TryBridgeBySimpleName_Bridges_WhenSignedRequestPktMatchesLoaded`
locks in that the signed-framework happy path still works.
- The three step-1 framework tests (System.Text.Json,
Logging.Abstractions, System.Text.Encodings.Web) now set the real
PKT on the request so they mirror how compiled AssemblyRefs reach
the bridge.
Step 4 success log moved from `Console.Error` to `Console.Out`. The
"file-system probe loaded X" message is purely informational; IDE
output panels treat stderr as red ink and were flagging successful
startup as if something had failed. Failure paths stay on stderr.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23306/wasm-skia-net9/index.html |
Closing — superseded by a different approachThis PR went through four iterations on the same branch and ultimately reached a structural dead end. Closing it (without merging) and starting fresh on a new branch is the cleaner path forward. Documenting the journey here so the lessons aren't lost. What we tried
Verified failure in productionPackage The host log shows no Crucially, the second failure is The structural insightThe DevServer host runs three
When a provider in ALC #2 registers This is the original sin of cross-ALC IoC and the reason the file-system probe couldn't succeed regardless of how robust it became. Next direction (the new PR will link back here)Revert the ALC isolation introduced by #23287. Use The cross-major-version scenarios that #23287 originally fixed (Kiota net8 → Two diagnostic additions to make future debugging easier:
Carries over to the new PR
Follow-up out of scope hereA CI-side validation in |
Summary
#23287 moved DevServer add-in loading from
Assembly.LoadFrom(everything inDefaultALC) into a shared isolatedAddInLoadContext. That fixed three cross-major-versionFileNotFoundExceptions (Kiota,Mcp,ModelContextProtocol) and must stay in place.Side effect: contract assemblies physically present in one add-in's directory but absent from every add-in's
.deps.jsoncould no longer be resolved across the ALC boundary.Uno.Licensing.Sdk.Contractsfalls into this bucket — the Settings add-in provides it, but the Mcp and HotDesign add-ins consume it via DI without listing it in their own.deps.json. At runtime this produces:The "Initializing Uno Platform Studio, please wait…" overlay never resolves because these two processors never register.
Fixes #23304.
Fix — zero knowledge of which add-ins are loaded
The DevServer host has no static list of which contract assemblies need to be shared (no white-list, no per-product glob). The published add-ins are not modified — they continue to ship as-is.
Root cause
The resolution chain inside
AddInLoadContext.Load(AssemblyName)has three steps:TryBridgeBySimpleName(Default, …)— already-loaded in Default ALC ?Default.LoadFromAssemblyName(…)— listed in the host TPA ?AssemblyDependencyResolver.ResolveAssemblyToPath(…)— listed in any.deps.json?AssemblyDependencyResolveronly consults.deps.json. It does not probe the file system. When a contract DLL is physically present in an add-in directory but absent from every add-in's.deps.json, all three steps return null and the runtime throwsFileNotFoundException. Before PR #23287,Assembly.LoadFrom's implicit directory probing masked this packaging quirk.Step 4 — file-system probe
AddInLoadContext.Loadgains a fourth, last-resort step: aDictionary<string,string>snapshot built at construction time enumerates every*.dllco-located with the registered add-ins, keyed by simple name. Step 4 looks up the snapshot andLoadFromAssemblyPath's the matching candidate into the shared add-in ALC. Every add-in then sees the sameTypeidentity and DI resolves cleanly.Properties:
LoadFromAssemblyPathfailures (BadImageFormatException, etc.) are caught and treated as misses so the chain stays consistent.AssemblyName.Namevalues containing path separators are rejected before any probe.System.Text.Encodings.Web 8.0.0.0ref to the host's loaded v9/v10.Asymmetric PKT match
TryBridgeBySimpleNameandAddInLoadContext.Loadstep 2 enforce a PKT match only when the request carries a non-empty PublicKeyToken. Signed frameworkAssemblyRefs (e.g.System.Text.Json,System.Text.Encodings.Webfrom compiled add-ins) require matching PKT — preventing identity swaps even if a same-name candidate sits in Default ALC. Unsigned requests (cross-add-in unsigned contracts) skip the check. This is identity validation, not an allow-list.Other cleanup
s_trustedPkts/IsTrustedPkt()and the misleading[ERROR] untrusted public key tokenwarning that the VS "Uno Platform" output panel flagged on every host startup.Console.Out(informational); only genuine failures stay onConsole.Error.DevServer_ShouldResolveSharedContractAcrossAddIns…fixes the--addinsarg format (semicolon-separated, not space-separated — the previous form silently dropped the consumer add-in).