Skip to content

Commit 2bd1701

Browse files
authored
Annotate Microsoft.CSharp with RequiresDynamicCode (#114346)
The public API surface looks exactly like RequiresUnreferencedCode, but the private implementation details vary slightly. I don't think there's a meaningful difference in the annotations for RDC vs RUC.
1 parent 84702c3 commit 2bd1701

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+426
-7
lines changed

src/libraries/Microsoft.CSharp/ref/Microsoft.CSharp.cs

+11
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,37 @@ namespace Microsoft.CSharp.RuntimeBinder
1010
public static partial class Binder
1111
{
1212
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")]
13+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")]
1314
public static System.Runtime.CompilerServices.CallSiteBinder BinaryOperation(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Linq.Expressions.ExpressionType operation, System.Type? context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo>? argumentInfo) { throw null; }
1415
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")]
16+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")]
1517
public static System.Runtime.CompilerServices.CallSiteBinder Convert(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type type, System.Type? context) { throw null; }
1618
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")]
19+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")]
1720
public static System.Runtime.CompilerServices.CallSiteBinder GetIndex(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type? context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo>? argumentInfo) { throw null; }
1821
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")]
22+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")]
1923
public static System.Runtime.CompilerServices.CallSiteBinder GetMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Type? context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo>? argumentInfo) { throw null; }
2024
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")]
25+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")]
2126
public static System.Runtime.CompilerServices.CallSiteBinder Invoke(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type? context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo>? argumentInfo) { throw null; }
2227
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")]
28+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")]
2329
public static System.Runtime.CompilerServices.CallSiteBinder InvokeConstructor(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type? context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo>? argumentInfo) { throw null; }
2430
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")]
31+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")]
2532
public static System.Runtime.CompilerServices.CallSiteBinder InvokeMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Collections.Generic.IEnumerable<System.Type>? typeArguments, System.Type? context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo>? argumentInfo) { throw null; }
2633
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")]
34+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")]
2735
public static System.Runtime.CompilerServices.CallSiteBinder IsEvent(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Type? context) { throw null; }
2836
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")]
37+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")]
2938
public static System.Runtime.CompilerServices.CallSiteBinder SetIndex(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type? context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo>? argumentInfo) { throw null; }
3039
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")]
40+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")]
3141
public static System.Runtime.CompilerServices.CallSiteBinder SetMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Type? context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo>? argumentInfo) { throw null; }
3242
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")]
43+
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")]
3344
public static System.Runtime.CompilerServices.CallSiteBinder UnaryOperation(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Linq.Expressions.ExpressionType operation, System.Type? context, System.Collections.Generic.IEnumerable<Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo>? argumentInfo) { throw null; }
3445
}
3546
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]

src/libraries/Microsoft.CSharp/src/Microsoft.CSharp.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<DefineConstants Condition="'$(EnableComBinder)' == 'true'">$(DefineConstants);ENABLECOMBINDER</DefineConstants>
1414
<AllowUnsafeBlocks Condition="'$(EnableComBinder)' == 'true'">true</AllowUnsafeBlocks>
1515
<DefineConstants>$(DefineConstants);LEGACY_GETRESOURCESTRING_USER</DefineConstants>
16-
<EnableAOTAnalyzer>false</EnableAOTAnalyzer>
16+
<EnableAOTAnalyzer>true</EnableAOTAnalyzer>
1717
</PropertyGroup>
1818

1919
<ItemGroup>

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Binder.cs

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder
1717
public static class Binder
1818
{
1919
internal const string TrimmerWarning = "Using dynamic types might cause types or members to be removed by trimmer.";
20+
internal const string DynamicCodeWarning = "The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.";
2021
//////////////////////////////////////////////////////////////////////
2122

2223
/// <summary>
@@ -28,6 +29,7 @@ public static class Binder
2829
/// <param name="argumentInfo">The sequence of <see cref="CSharpArgumentInfo"/> instances for the arguments to this operation.</param>
2930
/// <returns>Returns a new CSharp binary operation binder.</returns>
3031
[RequiresUnreferencedCode(TrimmerWarning)]
32+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
3133
public static CallSiteBinder BinaryOperation(
3234
CSharpBinderFlags flags,
3335
ExpressionType operation,
@@ -56,6 +58,7 @@ public static CallSiteBinder BinaryOperation(
5658
/// <param name="context">The <see cref="Type"/> that indicates where this operation is used.</param>
5759
/// <returns>Returns a new CSharp convert binder.</returns>
5860
[RequiresUnreferencedCode(TrimmerWarning)]
61+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
5962
public static CallSiteBinder Convert(
6063
CSharpBinderFlags flags,
6164
Type type,
@@ -83,6 +86,7 @@ public static CallSiteBinder Convert(
8386
/// <param name="argumentInfo">The sequence of <see cref="CSharpArgumentInfo"/> instances for the arguments to this operation.</param>
8487
/// <returns>Returns a new CSharp get index binder.</returns>
8588
[RequiresUnreferencedCode(TrimmerWarning)]
89+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
8690
public static CallSiteBinder GetIndex(
8791
CSharpBinderFlags flags,
8892
Type? context,
@@ -102,6 +106,7 @@ public static CallSiteBinder GetIndex(
102106
/// <param name="argumentInfo">The sequence of <see cref="CSharpArgumentInfo"/> instances for the arguments to this operation.</param>
103107
/// <returns>Returns a new CSharp get member binder.</returns>
104108
[RequiresUnreferencedCode(TrimmerWarning)]
109+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
105110
public static CallSiteBinder GetMember(
106111
CSharpBinderFlags flags,
107112
string name,
@@ -122,6 +127,7 @@ public static CallSiteBinder GetMember(
122127
/// <param name="argumentInfo">The sequence of <see cref="CSharpArgumentInfo"/> instances for the arguments to this operation.</param>
123128
/// <returns>Returns a new CSharp invoke binder.</returns>
124129
[RequiresUnreferencedCode(TrimmerWarning)]
130+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
125131
public static CallSiteBinder Invoke(
126132
CSharpBinderFlags flags,
127133
Type? context,
@@ -150,6 +156,7 @@ public static CallSiteBinder Invoke(
150156
/// <param name="argumentInfo">The sequence of <see cref="CSharpArgumentInfo"/> instances for the arguments to this operation.</param>
151157
/// <returns>Returns a new CSharp invoke member binder.</returns>
152158
[RequiresUnreferencedCode(TrimmerWarning)]
159+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
153160
public static CallSiteBinder InvokeMember(
154161
CSharpBinderFlags flags,
155162
string name,
@@ -188,6 +195,7 @@ public static CallSiteBinder InvokeMember(
188195
/// <param name="argumentInfo">The sequence of <see cref="CSharpArgumentInfo"/> instances for the arguments to this operation.</param>
189196
/// <returns>Returns a new CSharp invoke constructor binder.</returns>
190197
[RequiresUnreferencedCode(TrimmerWarning)]
198+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
191199
public static CallSiteBinder InvokeConstructor(
192200
CSharpBinderFlags flags,
193201
Type? context,
@@ -206,6 +214,7 @@ public static CallSiteBinder InvokeConstructor(
206214
/// <param name="context">The <see cref="System.Type"/> that indicates where this operation is used.</param>
207215
/// <returns>Returns a new CSharp is event binder.</returns>
208216
[RequiresUnreferencedCode(TrimmerWarning)]
217+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
209218
public static CallSiteBinder IsEvent(
210219
CSharpBinderFlags flags,
211220
string name,
@@ -224,6 +233,7 @@ public static CallSiteBinder IsEvent(
224233
/// <param name="argumentInfo">The sequence of <see cref="CSharpArgumentInfo"/> instances for the arguments to this operation.</param>
225234
/// <returns>Returns a new CSharp set index binder.</returns>
226235
[RequiresUnreferencedCode(TrimmerWarning)]
236+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
227237
public static CallSiteBinder SetIndex(
228238
CSharpBinderFlags flags,
229239
Type? context,
@@ -245,6 +255,7 @@ public static CallSiteBinder SetIndex(
245255
/// <param name="argumentInfo">The sequence of <see cref="CSharpArgumentInfo"/> instances for the arguments to this operation.</param>
246256
/// <returns>Returns a new CSharp set member binder.</returns>
247257
[RequiresUnreferencedCode(TrimmerWarning)]
258+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
248259
public static CallSiteBinder SetMember(
249260
CSharpBinderFlags flags,
250261
string name,
@@ -267,6 +278,7 @@ public static CallSiteBinder SetMember(
267278
/// <param name="argumentInfo">The sequence of <see cref="CSharpArgumentInfo"/> instances for the arguments to this operation.</param>
268279
/// <returns>Returns a new CSharp unary operation binder.</returns>
269280
[RequiresUnreferencedCode(TrimmerWarning)]
281+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
270282
public static CallSiteBinder UnaryOperation(
271283
CSharpBinderFlags flags,
272284
ExpressionType operation,

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/BinderHelper.cs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal static class BinderHelper
2121
private static MethodInfo s_SingleIsNaN;
2222

2323
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
24+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
2425
internal static DynamicMetaObject Bind(
2526
ICSharpBinder action,
2627
RuntimeBinder binder,
@@ -474,6 +475,7 @@ internal static bool CompareArgInfos(CSharpArgumentInfo[] argInfos, CSharpArgume
474475
}
475476

476477
#if !ENABLECOMBINDER
478+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
477479
internal static void ThrowIfUsingDynamicCom(DynamicMetaObject target)
478480
{
479481
if (target.LimitType.IsCOMObject)

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpBinaryOperationBinder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder
1717
/// Instances of this class are generated by the C# compiler.
1818
/// </summary>
1919
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
20+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
2021
internal sealed class CSharpBinaryOperationBinder : BinaryOperationBinder, ICSharpBinder
2122
{
2223
[ExcludeFromCodeCoverage(Justification = "Name should not be called for this binder")]

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpConvertBinder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Microsoft.CSharp.RuntimeBinder
1616
/// Instances of this class are generated by the C# compiler.
1717
/// </summary>
1818
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
19+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
1920
internal sealed class CSharpConvertBinder : ConvertBinder, ICSharpBinder
2021
{
2122
[ExcludeFromCodeCoverage(Justification = "Name should not be called for this binder")]

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpGetIndexBinder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Microsoft.CSharp.RuntimeBinder
1515
/// Instances of this class are generated by the C# compiler.
1616
/// </summary>
1717
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
18+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
1819
internal sealed class CSharpGetIndexBinder : GetIndexBinder, ICSharpBinder
1920
{
2021
public string Name => SpecialNames.Indexer;

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpGetMemberBinder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder
1717
/// Instances of this class are generated by the C# compiler.
1818
/// </summary>
1919
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
20+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
2021
internal sealed class CSharpGetMemberBinder : GetMemberBinder, IInvokeOnGetBinder, ICSharpBinder
2122
{
2223
public BindingFlag BindingFlags => BindingFlag.BIND_RVALUEREQUIRED;

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeBinder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Microsoft.CSharp.RuntimeBinder
1515
/// Represents a dynamic delegate-like call in C#, providing the binding semantics and the details about the operation.
1616
/// Instances of this class are generated by the C# compiler.
1717
/// </summary>
18+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
1819
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
1920
internal sealed class CSharpInvokeBinder : InvokeBinder, ICSharpInvokeOrInvokeMemberBinder
2021
{

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeConstructorBinder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Microsoft.CSharp.RuntimeBinder
1212
{
1313
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
14+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
1415
internal sealed class CSharpInvokeConstructorBinder : DynamicMetaObjectBinder, ICSharpInvokeOrInvokeMemberBinder
1516
{
1617
public BindingFlag BindingFlags => 0;

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeMemberBinder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder
1717
/// Instances of this class are generated by the C# compiler.
1818
/// </summary>
1919
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
20+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
2021
internal sealed class CSharpInvokeMemberBinder : InvokeMemberBinder, ICSharpInvokeOrInvokeMemberBinder
2122
{
2223
public BindingFlag BindingFlags => 0;

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpIsEventBinder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Microsoft.CSharp.RuntimeBinder
1313
/// Used to test whether a dynamic member over which += or -= is used is an event member.
1414
/// </summary>
1515
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
16+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
1617
internal sealed class CSharpIsEventBinder : DynamicMetaObjectBinder, ICSharpBinder
1718
{
1819
public BindingFlag BindingFlags => 0;

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpSetIndexBinder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Microsoft.CSharp.RuntimeBinder
1616
/// Instances of this class are generated by the C# compiler.
1717
/// </summary>
1818
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
19+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
1920
internal sealed class CSharpSetIndexBinder : SetIndexBinder, ICSharpBinder
2021
{
2122
public string Name => SpecialNames.Indexer;

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpSetMemberBinder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Microsoft.CSharp.RuntimeBinder
1616
/// Instances of this class are generated by the C# compiler.
1717
/// </summary>
1818
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
19+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
1920
internal sealed class CSharpSetMemberBinder : SetMemberBinder, ICSharpBinder
2021
{
2122
public BindingFlag BindingFlags => 0;

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpUnaryOperationBinder.cs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder
1717
/// Instances of this class are generated by the C# compiler.
1818
/// </summary>
1919
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
20+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
2021
internal sealed class CSharpUnaryOperationBinder : UnaryOperationBinder, ICSharpBinder
2122
{
2223
[ExcludeFromCodeCoverage(Justification = "Name should not be called for this binder")]

src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/BoundDispEvent.cs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Microsoft.CSharp.RuntimeBinder.ComInterop
1111
{
1212
[RequiresUnreferencedCode(Binder.TrimmerWarning)]
13+
[RequiresDynamicCode(Binder.DynamicCodeWarning)]
1314
internal sealed class BoundDispEvent : DynamicObject
1415
{
1516
private readonly object _rcw;

0 commit comments

Comments
 (0)