Skip to content

Fix Microsoft.CSharp dynamic code annotations - #132852

Open
eerhardt wants to merge 1 commit into
mainfrom
eerhardt-fix-csharp-dynamic-code-annotation
Open

Fix Microsoft.CSharp dynamic code annotations#132852
eerhardt wants to merge 1 commit into
mainfrom
eerhardt-fix-csharp-dynamic-code-annotation

Conversation

@eerhardt

@eerhardt eerhardt commented Aug 27, 2026

Copy link
Copy Markdown
Member

Summary

  • annotate ComObject.RcwToComObject with RequiresDynamicCode
  • propagate the requirement to ComMetaObject, which calls that method while constructing COM binding expressions

Reasoning

When creating an AOT-compatiblity test application, AOT analysis reports IL3050 from inside Microsoft.CSharp. RcwToComObject uses reflection to create a call to ObjectToComObject, which is annotated with both RequiresUnreferencedCode and RequiresDynamicCode. However, RcwToComObject only propagated RequiresUnreferencedCode. Propagating RequiresDynamicCode through RcwToComObject and ComMetaObject keeps the annotations consistent and prevents the warning from originating from an unannotated Microsoft.CSharp implementation path.

Testing

  • dotnet build in src/libraries/Microsoft.CSharp
  • dotnet build /t:test src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj (2,648 passed)

Note

This pull request description was generated by GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a4c4ef6c-a4f3-4d4b-8f75-1321394c795e
Copilot AI lite review requested due to automatic review settings August 27, 2026 19:46
@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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @phil-allen-msft, @333fred
See info in area-owners.md if you want to be subscribed.

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.

Pull request overview

This PR aligns Microsoft.CSharp’s COM interop binder annotations with the actual dynamic-code requirements by marking the COM binding expression construction path as RequiresDynamicCode, so AOT analysis warnings originate from correctly annotated APIs.

Changes:

  • Annotates ComObject.RcwToComObject with [RequiresDynamicCode(Binder.DynamicCodeWarning)] to match the dynamic-code requirement of the reflected ObjectToComObject target.
  • Propagates [RequiresDynamicCode] onto ComMetaObject, which constructs binding expressions using RcwToComObject.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComObject.cs Adds RequiresDynamicCode to RcwToComObject so the annotation matches the reflected call path used when building COM binding expressions.
src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComMetaObject.cs Adds RequiresDynamicCode to propagate the requirement to the caller that uses RcwToComObject during COM binding expression construction.

@333fred

333fred commented Aug 27, 2026

Copy link
Copy Markdown
Member

I know absolutely nothing about COM, so I'm tagging an expert to say if this seems reasonable @AaronRobinsonMSFT 🙂.

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

Ugh. Yes, this seems appropriate. Sorry it was missed.

/cc @jkoritzinsky and @elinor-fung

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.

7 participants