From 3e086821523994fbad092cbdf37cf420cb1e707c Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Tue, 7 May 2024 10:47:09 -0700 Subject: [PATCH 1/3] Update il2111.md Document confusing example of IL2111 warning. --- .../trimming/trim-warnings/il2111.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/core/deploying/trimming/trim-warnings/il2111.md b/docs/core/deploying/trimming/trim-warnings/il2111.md index b98fdb15e304b..515c295d5e00e 100644 --- a/docs/core/deploying/trimming/trim-warnings/il2111.md +++ b/docs/core/deploying/trimming/trim-warnings/il2111.md @@ -14,6 +14,8 @@ The trimmer can't guarantee that all requirements of the on its parameters or return type. + ```csharp void MethodWithRequirements([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type type) { @@ -25,3 +27,29 @@ void TestMethod() typeof(Test).GetMethod("MethodWithRequirements"); } ``` + +Also, a implies reflection access over all of the listed . This means that when a type is passed to a parameter, field, generic parameter, or return value annotated with .NET tooling assumes that all public methods are accessed via reflection. If a type that contains a method with an annotated parameter or return value is passed to a location annotated with , then IL2111 will be raised. + +```csharp +class TypeWithAnnotatedMethod +{ + void MethodWithRequirements([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] Type type) + { + } +} + +class OtherType +{ + void AccessMethodViaReflection([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type type) + { + } + + void PassTypeToAnnotatedMethod() + { + // IL2111: Method 'MethodWithRequirements' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method. + AccessMethodViaReflection(typeof(TypeWithAnnotatedMethod)); + } +} +``` + + From 3b5cc7de002c10b6980aa637c40f672e3b3a9f3c Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Tue, 7 May 2024 10:49:42 -0700 Subject: [PATCH 2/3] Update il2111.md --- docs/core/deploying/trimming/trim-warnings/il2111.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/deploying/trimming/trim-warnings/il2111.md b/docs/core/deploying/trimming/trim-warnings/il2111.md index 515c295d5e00e..f74c50d47e25c 100644 --- a/docs/core/deploying/trimming/trim-warnings/il2111.md +++ b/docs/core/deploying/trimming/trim-warnings/il2111.md @@ -28,7 +28,7 @@ void TestMethod() } ``` -Also, a implies reflection access over all of the listed . This means that when a type is passed to a parameter, field, generic parameter, or return value annotated with .NET tooling assumes that all public methods are accessed via reflection. If a type that contains a method with an annotated parameter or return value is passed to a location annotated with , then IL2111 will be raised. +This warning can also be caused by passing a type to a field, paramter, argument, or return value that is annotated with . implies reflection access over all of the listed . This means that when a type is passed to a parameter, field, generic parameter, or return value annotated with .NET tooling assumes that all public methods are accessed via reflection. If a type that contains a method with an annotated parameter or return value is passed to a location annotated with , then IL2111 will be raised. ```csharp class TypeWithAnnotatedMethod From 0c7b727403016ce7c149e1715bc00ce62df9f33c Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Tue, 7 May 2024 10:50:23 -0700 Subject: [PATCH 3/3] Remove extra lines --- docs/core/deploying/trimming/trim-warnings/il2111.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/core/deploying/trimming/trim-warnings/il2111.md b/docs/core/deploying/trimming/trim-warnings/il2111.md index f74c50d47e25c..58b978d673e31 100644 --- a/docs/core/deploying/trimming/trim-warnings/il2111.md +++ b/docs/core/deploying/trimming/trim-warnings/il2111.md @@ -51,5 +51,3 @@ class OtherType } } ``` - -