[DuckTyping] Generate proxies in target AssemblyLoadContext - #9167
Conversation
BenchmarksBenchmark execution time: 2026-09-07 15:08:56 Comparing candidate commit 004ce88 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 72 metrics, 0 unstable metrics, 67 known flaky benchmarks, 59 flaky benchmarks without significant changes.
|
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (9167) and master. ✅ No regressions detected |
pablomartinezbernardo
left a comment
There was a problem hiding this comment.
Fixes the issue seen empirically at #8911
andrewlock
left a comment
There was a problem hiding this comment.
LGTM, mostly minor comments about the build side.
I wonder if we should be trying to fast-path the default ALC to avoid the reflection call (mostly for <.NET 6)?
Summary of changes
Reason for change
Azure Functions can load assemblies with the same identity into the default and a custom
AssemblyLoadContext. DuckTyping previously generated its proxy in the default context, so the proxy could resolve a field dependency from the wrong context and throwMissingFieldException.Implementation details
net6.0tracer build, which is selected on .NET 6 and later, enter contextual reflection for the target assembly while defining the dynamic proxy assembly.netstandard2.0andnetcoreapp3.1tracer builds, invokeAssemblyBuilder.DefineDynamicAssemblyfrom a one-shotDynamicMethodassociated with the target manifest module. This selects the target load context on .NET Core 2.1 through .NET 5, where contextual reflection cannot solve this case.Typeidentities. BecauseTypeidentity includes its load context, the cache already isolates types loaded into different contexts. A new test verifies reuse within one context and separation across contexts containing assemblies with the same identity.netstandard2.0fixture projects to provide the target and its duplicated dependency. These projects are test-only build inputs and add no dependencies to the productionDatadog.Traceassembly or package.AssemblyLoadContext.ContextualReflectionScope.Test coverage
netcoreapp2.1,netcoreapp3.0,netcoreapp3.1,net5.0,net6.0, andnet10.0.netcoreapp2.1(10,925 passed),netcoreapp3.1(10,926 passed), andnet6.0(10,926 passed).Datadog.Tracecompiled successfully fornet461with 0 warnings and 0 errors.Other details
Includes and extends the reproduction from #9156.