Skip to content

Commit 0cfa25b

Browse files
committed
Add missing docs for trim warnings
1 parent ec12733 commit 0cfa25b

File tree

6 files changed

+137
-6
lines changed

6 files changed

+137
-6
lines changed

docs/core/deploying/trimming/trim-warnings/il2070.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ The target location declares some requirements on the type value via its <xref:S
1515
## Example
1616

1717
```csharp
18-
void GenericWithAnnotation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>()
19-
{
20-
}
21-
2218
void TestMethod(Type type)
2319
{
24-
// IL2070 Trim analysis: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])'. The parameter 'type' of method 'TestMethod' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
25-
typeof(AnnotatedGenerics).GetMethod(nameof(GenericWithAnnotation)).MakeGenericMethod(type);
20+
// IL2070 Trim analysis: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String)'. The parameter 'type' of method 'TestMethod(Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
21+
type.GetMethod("Method");
2622
}
2723
```
2824

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: "IL2071: 'target generic parameter' generic argument does not satisfy 'DynamicallyAccessedMembersAttribute' in 'target method'. The parameter 'source parameter' of method 'source method' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to."
3+
description: "Learn about trim warning IL2071: DynamicallyAccessedMembersMismatchParameterTargetsGenericParameter"
4+
ms.date: 08/23/2024
5+
author: svbomer
6+
f1_keywords:
7+
- "IL2071"
8+
---
9+
# IL2071: 'target generic parameter' generic argument does not satisfy 'DynamicallyAccessedMembersAttribute' in 'target method'. The parameter 'source parameter' of method 'source method' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to
10+
11+
## Cause
12+
13+
The target location declares some requirements on the type value via its <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute>. Those requirements must be met by those declared on the source value also via the <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute>. The source value can declare more requirements than the target, if necessary.
14+
15+
## Example
16+
17+
```csharp
18+
public void GenericWithAnnotation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>()
19+
{
20+
}
21+
22+
void TestMethod(Type type)
23+
{
24+
// IL2071 Trim Analysis: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in 'GenericWithAnnotation<T>()'. The parameter 'type' of method 'TestMethod(Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
25+
typeof(AnnotatedGenerics).GetMethod(nameof(GenericWithAnnotation)).MakeGenericMethod(type);
26+
}
27+
```
28+
29+
## Fixing
30+
31+
See [Fixing Warnings](../fixing-warnings.md#functionality-with-requirements-on-its-input) for guidance.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: "IL2076: 'target generic parameter' generic argument does not satisfy 'DynamicallyAccessedMembersAttribute' in 'target method'. The return value of method 'source method' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
3+
description: "Learn about trim warning IL2076: DynamicallyAccessedMembersMismatchMethodReturnTypeTargetsGenericParameter"
4+
ms.date: 08/23/2024
5+
author: svbomer
6+
f1_keywords:
7+
- "IL2076"
8+
---
9+
# IL2076: 'target generic parameter' generic argument does not satisfy 'DynamicallyAccessedMembersAttribute' in 'target method'. The return value of method 'source method' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to
10+
11+
## Cause
12+
13+
The target location declares some requirements on the type value via its <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute>. Those requirements must be met by those declared on the source value also via the <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute>. The source value can declare more requirements than the target, if necessary.
14+
15+
## Example
16+
17+
```csharp
18+
public void GenericWithAnnotation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>()
19+
{
20+
}
21+
22+
Type GetType() => typeof(int);
23+
24+
void TestMethod()
25+
{
26+
// IL2076 Trim Analysis: AnnotatedGenerics.TestMethod(Type): 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in 'GenericWithAnnotation<T>()'. The return value of method 'GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to
27+
typeof(AnnotatedGenerics).GetMethod(nameof(GenericWithAnnotation)).MakeGenericMethod(GetType());
28+
}
29+
```
30+
31+
## Fixing
32+
33+
See [Fixing Warnings](../fixing-warnings.md#functionality-with-requirements-on-its-input) for guidance.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: "IL2081: 'target generic parameter' generic argument does not satisfy 'DynamicallyAccessedMembersAttribute' in 'target method'. The field 'source field' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
3+
description: "Learn about trim warning IL2081: DynamicallyAccessedMembersMismatchFieldTargetsGenericParameter"
4+
ms.date: 08/23/2024
5+
author: svbomer
6+
f1_keywords:
7+
- "IL2081"
8+
---
9+
# IL2081: 'target generic parameter' generic argument does not satisfy 'DynamicallyAccessedMembersAttribute' in 'target method'. The field 'source field' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to
10+
11+
## Cause
12+
13+
The target location declares some requirements on the type value via its <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute>. Those requirements must be met by those declared on the source value also via the <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute>. The source value can declare more requirements than the target, if necessary.
14+
15+
## Example
16+
17+
```csharp
18+
public void GenericWithAnnotation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] T>()
19+
{
20+
}
21+
22+
Type typeField;
23+
24+
void TestMethod()
25+
{
26+
// IL2081 Trim Analysis: 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in 'GenericWithAnnotation<T>()'. The field 'typeField' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
27+
typeof(AnnotatedGenerics).GetMethod(nameof(GenericWithAnnotation)).MakeGenericMethod(typeField);
28+
}
29+
```
30+
31+
## Fixing
32+
33+
See [Fixing Warnings](../fixing-warnings.md#functionality-with-requirements-on-its-input) for guidance.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: "IL2122: Type 'type' is not assembly qualified. Type name strings used for dynamically accessing a type should be assembly qualified."
3+
description: "Learn about trim warning IL2122: TypeNameIsNotAssemblyQualified"
4+
ms.date: 08/23/24
5+
author: svbomer
6+
f1_keywords:
7+
- "IL2122"
8+
---
9+
# IL2122: Type 'type' is not assembly qualified. Type name strings used for dynamically accessing a type should be assembly qualified
10+
11+
## Cause
12+
13+
Type name strings representing dynamically accessed types must be assembly qualified. Otherwise, the lookup semantics of `Type.GetType` will search the assembly with the `Type.GetType` callsite and the core library. The assembly with the `Type.GetType` callsite may be different than the assembly which passes the type name string to a location with `DynamicallyAccessedMembersAttribute`, so the tooling cannot determine which assemblies to search.
14+
15+
## Example
16+
17+
```csharp
18+
void TestInvalidTypeName()
19+
{
20+
// IL2122: Type 'UnqualifiedTypeName' is not assembly qualified. Type name strings used for dynamically accessing a type should be assembly qualified.
21+
RequirePublicMethodOnAType("UnqualifiedTypeName");
22+
}
23+
24+
void RequirePublicMethodOnAType(
25+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
26+
string typeName)
27+
{
28+
Type.GetType(typeName);
29+
}
30+
```

docs/navigate/devops-testing/toc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ items:
381381
href: ../../core/deploying/trimming/trim-warnings/il2069.md
382382
- name: IL2070
383383
href: ../../core/deploying/trimming/trim-warnings/il2070.md
384+
- name: IL2071
385+
href: ../../core/deploying/trimming/trim-warnings/il2071.md
384386
- name: IL2072
385387
href: ../../core/deploying/trimming/trim-warnings/il2072.md
386388
- name: IL2073
@@ -389,6 +391,8 @@ items:
389391
href: ../../core/deploying/trimming/trim-warnings/il2074.md
390392
- name: IL2075
391393
href: ../../core/deploying/trimming/trim-warnings/il2075.md
394+
- name: IL2076
395+
href: ../../core/deploying/trimming/trim-warnings/il2076.md
392396
- name: IL2077
393397
href: ../../core/deploying/trimming/trim-warnings/il2077.md
394398
- name: IL2078
@@ -397,6 +401,8 @@ items:
397401
href: ../../core/deploying/trimming/trim-warnings/il2079.md
398402
- name: IL2080
399403
href: ../../core/deploying/trimming/trim-warnings/il2080.md
404+
- name: IL2081
405+
href: ../../core/deploying/trimming/trim-warnings/il2081.md
400406
- name: IL2082
401407
href: ../../core/deploying/trimming/trim-warnings/il2082.md
402408
- name: IL2083
@@ -467,6 +473,8 @@ items:
467473
href: ../../core/deploying/trimming/trim-warnings/il2116.md
468474
- name: IL2117
469475
href: ../../core/deploying/trimming/trim-warnings/il2117.md
476+
- name: IL2122
477+
href: ../../core/deploying/trimming/trim-warnings/il2122.md
470478
- name: Native AOT deployment model
471479
items:
472480
- name: Overview

0 commit comments

Comments
 (0)