Skip to content

Remove dead NativeAOT dynamic-delegate path from System.Delegate#131150

Merged
MichalStrehovsky merged 2 commits into
mainfrom
copilot/remove-dead-nativeaot-dynamic-delegate-path
Jul 22, 2026
Merged

Remove dead NativeAOT dynamic-delegate path from System.Delegate#131150
MichalStrehovsky merged 2 commits into
mainfrom
copilot/remove-dead-nativeaot-dynamic-delegate-path

Conversation

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

main PR N/A

Description

Delegate.IsDynamicDelegate() in NativeAOT checked an impossible condition (GetThunk(MulticastThunk) == IntPtr.Zero), leaving an unreachable DynamicInvokeImpl branch. This change removes that dead representation check and keeps DynamicInvoke on the normal reflection-based invoke path.

  • Core runtime cleanup

    • Deleted IsDynamicDelegate().
    • Removed unreachable dynamic-delegate branch from DynamicInvokeImpl.
    • Removed obsolete CombineImpl guard that depended on IsDynamicDelegate().
  • Behavior-preserving simplification

    • Retained ReflectionAugments.GetDelegateDynamicInvokeInfo(GetType()).
    • Retained invoke-time exception wrapping (wrapInTargetInvocationException: true).
    • Retained debugger-step annotation behavior.
  • Scope control

    • Reviewed NativeAOT/runtime/compiler/libraries/tests for code solely tied to this obsolete path.
    • Removed only code directly coupled to that path; no unrelated thunk machinery changes.
[DebuggerGuidedStepThroughAttribute]
protected virtual object? DynamicInvokeImpl(object?[]? args)
{
    DynamicInvokeInfo dynamicInvokeInfo = ReflectionAugments.GetDelegateDynamicInvokeInfo(GetType());

    object? result = dynamicInvokeInfo.Invoke(_target, _methodPtr,
        args, binderBundle: null, wrapInTargetInvocationException: true);
    DebugAnnotations.PreviousCallContainsDebuggerStepInCode();
    return result;
}

Customer Impact

Lower maintenance risk in delegate invocation code by removing unreachable logic and redundant branching in a core runtime type.

Regression

Not a recent regression fix; this is dead-code removal and path simplification.

Testing

Focused validation was run to ensure normal DynamicInvoke behavior remains intact (including targeted delegate DynamicInvoke coverage) and CoreLib/NativeAOT build viability was rechecked.

Risk

Low. Narrowly scoped to deleting unreachable logic and preserving the existing active invocation path.

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

Copilot AI review requested due to automatic review settings July 21, 2026 14:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
16 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 21, 2026 14:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Copilot AI changed the title [WIP] Remove dead NativeAOT dynamic-delegate path from System.Delegate Remove dead NativeAOT dynamic-delegate path from System.Delegate Jul 21, 2026
Copilot AI requested a review from MichalStrehovsky July 21, 2026 15:01
@MichalStrehovsky
MichalStrehovsky marked this pull request as ready for review July 22, 2026 01:12
@MichalStrehovsky
MichalStrehovsky merged commit df8fb5a into main Jul 22, 2026
108 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the copilot/remove-dead-nativeaot-dynamic-delegate-path branch July 22, 2026 01:13
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@MichalStrehovsky

Copy link
Copy Markdown
Member

@MichalPetryka the merge conflict you requested is now in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants