Fix Microsoft.CSharp dynamic code annotations - #132852
Open
eerhardt wants to merge 1 commit into
Open
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a4c4ef6c-a4f3-4d4b-8f75-1321394c795e
|
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. |
Contributor
|
Tagging subscribers to this area: @phil-allen-msft, @333fred |
Contributor
There was a problem hiding this comment.
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.RcwToComObjectwith[RequiresDynamicCode(Binder.DynamicCodeWarning)]to match the dynamic-code requirement of the reflectedObjectToComObjecttarget. - Propagates
[RequiresDynamicCode]ontoComMetaObject, which constructs binding expressions usingRcwToComObject.
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. |
Member
|
I know absolutely nothing about COM, so I'm tagging an expert to say if this seems reasonable @AaronRobinsonMSFT 🙂. |
This was referenced Aug 28, 2026
Member
|
Ugh. Yes, this seems appropriate. Sorry it was missed. /cc @jkoritzinsky and @elinor-fung |
AaronRobinsonMSFT
approved these changes
Aug 28, 2026
jkoritzinsky
approved these changes
Aug 28, 2026
elinor-fung
approved these changes
Aug 28, 2026
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
ComObject.RcwToComObjectwithRequiresDynamicCodeComMetaObject, which calls that method while constructing COM binding expressionsReasoning
When creating an AOT-compatiblity test application, AOT analysis reports
IL3050from inside Microsoft.CSharp.RcwToComObjectuses reflection to create a call toObjectToComObject, which is annotated with bothRequiresUnreferencedCodeandRequiresDynamicCode. However,RcwToComObjectonly propagatedRequiresUnreferencedCode. PropagatingRequiresDynamicCodethroughRcwToComObjectandComMetaObjectkeeps the annotations consistent and prevents the warning from originating from an unannotated Microsoft.CSharp implementation path.Testing
dotnet buildinsrc/libraries/Microsoft.CSharpdotnet 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.