Skip to content

Commit

Permalink
Add STJ source gen diagnostics (#37777)
Browse files Browse the repository at this point in the history
  • Loading branch information
gewarren authored Oct 30, 2023
1 parent 0577a60 commit 3b522b7
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 22 deletions.
4 changes: 0 additions & 4 deletions .openpublishing.redirection.fundamentals.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@
"source_path_from_root": "/docs/fundamentals/syslib-diagnostics/syslib1029.md",
"redirect_url": "/dotnet/fundamentals/syslib-diagnostics/source-generator-overview"
},
{
"source_path_from_root": "/docs/fundamentals/syslib-diagnostics/syslib1039.md",
"redirect_url": "/dotnet/fundamentals/syslib-diagnostics/source-generator-overview"
},
{
"source_path_from_root": "/docs/fundamentals/syslib-diagnostics/syslib1040.md",
"redirect_url": "/dotnet/fundamentals/syslib-diagnostics/syslib1040-1049"
Expand Down
56 changes: 39 additions & 17 deletions docs/fundamentals/syslib-diagnostics/source-generator-overview.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Analyzer diagnostics in .NET 6+
description: Learn about analyzer diagnostics created by source generators in .NET 6 and later versions that produce SYSLIB compiler warnings.
ms.date: 05/10/2023
ms.date: 10/27/2023
---

# Source-generator diagnostics in .NET 6+
Expand Down Expand Up @@ -45,20 +45,20 @@ The following table provides an index to the `SYSLIB1XXX` diagnostics in .NET 6
| [SYSLIB1023][1023] | Generating more than six arguments is not supported |
| SYSLIB1024 | Logging method argument uses unsupported `out` parameter modifier |
| SYSLIB1025 | Multiple logging methods cannot use the same event name within a class |
| SYSLIB1026 | (Reserved for logging.) |
| SYSLIB1026 | C# language version not supported by the logging source generator. |
| SYSLIB1027 | (Reserved for logging.) |
| SYSLIB1028 | (Reserved for logging.) |
| SYSLIB1029 | (Reserved for logging.) |
| [SYSLIB1030][1030] | The `System.Text.Json` source generator did not generate serialization metadata for type |
| [SYSLIB1031][1031] | The `System.Text.Json` source generator encountered a duplicate `JsonTypeInfo` property name |
| [SYSLIB1032][1032] | The `System.Text.Json` source generator encountered a context class that is not partial |
| [SYSLIB1033][1033] | The `System.Text.Json` source generator encountered a type that has multiple `[JsonConstructor]` annotations |
| SYSLIB1034 | (Reserved for System.Text.Json.SourceGeneration.) |
| [SYSLIB1034][1034] | JsonSourceGenerator encountered a `JsonStringEnumConverter` annotation |
| [SYSLIB1035][1035] | The `System.Text.Json` source generator encountered a type that has multiple `[JsonExtensionData]` annotations |
| [SYSLIB1036][1036] | The `System.Text.Json` source generator encountered an invalid `[JsonExtensionData]` annotation |
| [SYSLIB1037][1037] | The `System.Text.Json` source generator encountered a type with init-only properties for which deserialization is not supported |
| [SYSLIB1038][1038] | The `System.Text.Json` source generator encountered a property annotated with `[JsonInclude]` that has inaccessible accessors |
| SYSLIB1039 | (ID is reserved for System.Text.Json.SourceGeneration.) |
| [SYSLIB1039][1039] | JsonSourceGenerator encountered a `JsonDerivedTypeAttribute` annotation with `JsonSourceGenerationMode.Serialization` enabled |
| [SYSLIB1040][1040] | Invalid <xref:System.Text.RegularExpressions.GeneratedRegexAttribute> usage. |
| [SYSLIB1041][1041] | Multiple <xref:System.Text.RegularExpressions.GeneratedRegexAttribute> attributes were applied to the same method, but only one is allowed. |
| [SYSLIB1042][1042] | The specified regular expression is invalid. |
Expand Down Expand Up @@ -111,19 +111,19 @@ The following table provides an index to the `SYSLIB1XXX` diagnostics in .NET 6
| [SYSLIB1089][1089] | (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.) |
| [SYSLIB1090][1090] | Invalid `GeneratedComInterfaceAttribute` usage. |
| [SYSLIB1091][1091] | Method is declared in different partial declaration than the `GeneratedComInterface` attribute. |
| [SYSLIB1092][1092] | (Reserved for Microsoft.Interop.ComInteropGenerator.) |
| [SYSLIB1093][1093] | (Reserved for Microsoft.Interop.ComInteropGenerator.) |
| [SYSLIB1094][1094] | (Reserved for Microsoft.Interop.ComInteropGenerator.) |
| [SYSLIB1095][1095] | (Reserved for Microsoft.Interop.ComInteropGenerator.) |
| [SYSLIB1096][1096] | (Reserved for Microsoft.Interop.ComInteropGenerator.) |
| [SYSLIB1097][1097] | (Reserved for Microsoft.Interop.ComInteropGenerator.) |
| [SYSLIB1098][1098] | (Reserved for Microsoft.Interop.ComInteropGenerator.) |
| [SYSLIB1099][1099] | (Reserved for Microsoft.Interop.ComInteropGenerator.) |
| [SYSLIB1100][1100] | Type is not supported. |
| [SYSLIB1101][1101] | Property on type is not supported. |
| [SYSLIB1102][1102] | Project's language version must be at least C# 11. |
| [SYSLIB1103][1103] | Value types are invalid inputs to configuration 'Bind' methods. |
| [SYSLIB1104][1104] | Generator cannot determine the target configuration type. |
| [SYSLIB1092][1092] | Usage of `LibraryImport` or `GeneratedComInterface` attribute does not follow recommendation. |
| [SYSLIB1093][1093] | Analysis for COM interface generation has failed. |
| [SYSLIB1094][1094] | The base COM interface failed to generate source. Code will not be generated for this interface. |
| [SYSLIB1095][1095] | Invalid `GeneratedComClassAttribute` usage. |
| [SYSLIB1096][1096] | Use `GeneratedComInterfaceAttribute` instead of `ComImportAttribute` to generate COM marshalling code at compile time. |
| [SYSLIB1097][1097] | This type implements at least one type with the `GeneratedComInterfaceAttribute` attribute. Add the `GeneratedComClassAttribute` to enable passing this type to COM and exposing the COM interfaces for the types with the `GeneratedComInterfaceAttribute` from objects of this type. |
| [SYSLIB1098][1098] | .NET COM hosting with `EnableComHosting` only supports built-in COM interop. It does not support source-generated COM interop with `GeneratedComInterfaceAttribute`. |
| [SYSLIB1099][1099] | COM Interop APIs on `System.Runtime.InteropServices.Marshal` do not support source-generated COM and will fail at run time. |
| [SYSLIB1100][1100] | Configuration binding generator: Type is not supported. |
| [SYSLIB1101][1101] | Configuration binding generator: Property on type is not supported. |
| [SYSLIB1102][1102] | Configuration binding generator: Project's language version must be at least C# 11. |
| [SYSLIB1103][1103] | Configuration binding generator: Value types are invalid inputs to configuration 'Bind' methods. |
| [SYSLIB1104][1104] | Configuration binding generator: Generator cannot determine the target configuration type. |
| [SYSLIB1105][1105] | (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.) |
| [SYSLIB1106][1106] | (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)(Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.) |
| [SYSLIB1107][1107] | (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.) |
Expand Down Expand Up @@ -157,6 +157,16 @@ The following table provides an index to the `SYSLIB1XXX` diagnostics in .NET 6
| [SYSLIB1217][1217] | The validation attribute is only applicable to properties of type string, array, or `ICollection`; it cannot be used with other types. |
| [SYSLIB1218][1218] | (Reserved for Microsoft.Extensions.Options.SourceGeneration.) |
| [SYSLIB1219][1219] | (Reserved for Microsoft.Extensions.Options.SourceGeneration.) |
| [SYSLIB1220][1220] | JsonSourceGenerator encountered a [JsonConverterAttribute] with an invalid type argument. |
| [SYSLIB1221][1221] | JsonSourceGenerator does not support this C# language version. |
| [SYSLIB1222][1222] | Constructor annotated with JsonConstructorAttribute is inaccessible. |
| [SYSLIB1223][1223] | Constructor annotated with JsonConstructorAttribute is inaccessible. |
| [SYSLIB1224][1224] | Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. |
| [SYSLIB1225][1225] | (Reserved for System.Text.Json.SourceGeneration.) |
| [SYSLIB1226][1226] | (Reserved for System.Text.Json.SourceGeneration.) |
| [SYSLIB1227][1227] | (Reserved for System.Text.Json.SourceGeneration.) |
| [SYSLIB1228][1228] | (Reserved for System.Text.Json.SourceGeneration.) |
| [SYSLIB1229][1229] | (Reserved for System.Text.Json.SourceGeneration.) |

<!-- Include adds ## Suppress warnings (H2 heading) -->
[!INCLUDE [suppress-source-generator-diagnostics](includes/suppress-source-generator-diagnostics.md)]
Expand Down Expand Up @@ -187,10 +197,12 @@ The following table provides an index to the `SYSLIB1XXX` diagnostics in .NET 6
[1031]: syslib1031.md
[1032]: syslib1032.md
[1033]: syslib1033.md
[1034]: syslib1034.md
[1035]: syslib1035.md
[1036]: syslib1036.md
[1037]: syslib1037.md
[1038]: syslib1038.md
[1039]: syslib1039.md
[1040]: syslib1040-1049.md
[1041]: syslib1040-1049.md
[1042]: syslib1040-1049.md
Expand Down Expand Up @@ -289,3 +301,13 @@ The following table provides an index to the `SYSLIB1XXX` diagnostics in .NET 6
[1217]: syslib1201-1219.md
[1218]: syslib1201-1219.md
[1219]: syslib1201-1219.md
[1220]: syslib1220-1229.md
[1221]: syslib1220-1229.md
[1222]: syslib1220-1229.md
[1223]: syslib1220-1229.md
[1224]: syslib1220-1229.md
[1225]: syslib1220-1229.md
[1226]: syslib1220-1229.md
[1227]: syslib1220-1229.md
[1228]: syslib1220-1229.md
[1229]: syslib1220-1229.md
15 changes: 15 additions & 0 deletions docs/fundamentals/syslib-diagnostics/syslib1034.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: SYSLIB1034 error
description: Learn about the diagnostic that generates compile-time error SYSLIB1034.
ms.date: 10/26/2023
---

# SYSLIB1034: JsonSourceGenerator encountered a [JsonStringEnumConverter] annotation

The non-generic <xref:System.Text.Json.Serialization.JsonStringEnumConverter> requires dynamic code and can't be used with source generation.

## Workarounds

Use <xref:System.Text.Json.Serialization.JsonStringEnumConverter%601> instead, which doesn't require run-time code generation.

[!INCLUDE [suppress-syslib-warning](includes/suppress-source-generator-diagnostics.md)]
15 changes: 15 additions & 0 deletions docs/fundamentals/syslib-diagnostics/syslib1039.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: SYSLIB1039 error
description: Learn about the diagnostic that generates compile-time error SYSLIB1039.
ms.date: 10/26/2023
---

# SYSLIB1039: JsonSourceGenerator encountered a `JsonDerivedTypeAttribute` annotation with `JsonSourceGenerationMode.Serialization` enabled

<xref:System.Text.Json.Serialization.JsonDerivedTypeAttribute> annotations are supported for source generation, but not for contexts that are annotated with <xref:System.Text.Json.Serialization.JsonSourceGenerationMode.Serialization?displayProperty=nameWithType>. That is, the attribute works with the metadata source generator, but not in fast-path methods.

## Workarounds

Remove the attribute, or remove the <xref:System.Text.Json.Serialization.JsonSourceGenerationMode.Serialization?displayProperty=nameWithType> annotation from your serialization context.

[!INCLUDE [suppress-syslib-warning](includes/suppress-source-generator-diagnostics.md)]
10 changes: 9 additions & 1 deletion docs/fundamentals/syslib-diagnostics/syslib1090-1099.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: SYSLIB diagnostics for Microsoft.Interop.COMInteropGenerator
description: Learn about the COM interop source-generation analyzers that generate compile-time suggestions SYSLIB1090 through SYSLIB1099.
ms.date: 05/10/2023
ms.date: 10/28/2023
---
# SYSLIB diagnostics for COM interop source generation

Expand All @@ -11,3 +11,11 @@ The following table shows the diagnostic IDs for COM interop source-generation a
| - | - |
| `SYSLIB1090` | Invalid `GeneratedComInterfaceAttribute` usage. |
| `SYSLIB1091` | Method is declared in different partial declaration than the `GeneratedComInterface` attribute. To ensure reliable calculation for virtual method table offsets, all methods must be declared in the same partial definition of a `GeneratedComInterface`-attributed interface type. |
| `SYSLIB1092` | Usage of `LibraryImport` or `GeneratedComInterface` attribute does not follow recommendation. |
| `SYSLIB1093` | Analysis for COM interface generation has failed. |
| `SYSLIB1094` | The base COM interface failed to generate source. Code will not be generated for this interface. |
| `SYSLIB1095` | Invalid `GeneratedComClassAttribute` usage. |
| `SYSLIB1096` | Use `GeneratedComInterfaceAttribute` instead of `ComImportAttribute` to generate COM marshalling code at compile time. |
| `SYSLIB1097` | This type implements at least one type with the `GeneratedComInterfaceAttribute` attribute. Add the `GeneratedComClassAttribute` to enable passing this type to COM and exposing the COM interfaces for the types with the `GeneratedComInterfaceAttribute` from objects of this type. |
| `SYSLIB1098` | .NET COM hosting with `EnableComHosting` only supports built-in COM interop. It does not support source-generated COM interop with `GeneratedComInterfaceAttribute`. |
| `SYSLIB1099` | COM Interop APIs on `System.Runtime.InteropServices.Marshal` do not support source-generated COM and will fail at run time. |
21 changes: 21 additions & 0 deletions docs/fundamentals/syslib-diagnostics/syslib1220-1229.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: SYSLIB diagnostics for System.Text.Json.SourceGeneration
description: Learn about the System.Text.Json source-generation analyzers that generate compile-time suggestions SYSLIB1220 through SYSLIB1229.
ms.date: 10/24/2023
---
# SYSLIB diagnostics for System.Text.Json source generation

The following table shows the diagnostic IDs for System.Text.Json source-generation analyzers in .NET 8 and later versions.

| Diagnostic ID | Description |
| - | - |
| `SYSLIB1220` | JsonSourceGenerator encountered a `JsonConverterAttribute` with an invalid type argument. |
| `SYSLIB1221` | JsonSourceGenerator does not support this C# language version. |
| `SYSLIB1222` | Constructor annotated with `JsonConstructorAttribute` is inaccessible. |
| `SYSLIB1223` | Attributes deriving from `JsonConverterAttribute` are not supported by the source generator. |
| `SYSLIB1224` | Types annotated with `JsonSerializableAttribute` must be classes deriving from `JsonSerializerContext`. |
| `SYSLIB1225` | Reserved for System.Text.Json.SourceGeneration. |
| `SYSLIB1226` | Reserved for System.Text.Json.SourceGeneration. |
| `SYSLIB1227` | Reserved for System.Text.Json.SourceGeneration. |
| `SYSLIB1228` | Reserved for System.Text.Json.SourceGeneration. |
| `SYSLIB1229` | Reserved for System.Text.Json.SourceGeneration. |
7 changes: 7 additions & 0 deletions docs/navigate/tools-diagnostics/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,8 @@ items:
href: ../../fundamentals/syslib-diagnostics/syslib1032.md
- name: SYSLIB1033
href: ../../fundamentals/syslib-diagnostics/syslib1033.md
- name: SYSLIB1034
href: ../../fundamentals/syslib-diagnostics/syslib1034.md
- name: SYSLIB1035
href: ../../fundamentals/syslib-diagnostics/syslib1035.md
- name: SYSLIB1036
Expand All @@ -1745,6 +1747,8 @@ items:
href: ../../fundamentals/syslib-diagnostics/syslib1037.md
- name: SYSLIB1038
href: ../../fundamentals/syslib-diagnostics/syslib1038.md
- name: SYSLIB1039
href: ../../fundamentals/syslib-diagnostics/syslib1039.md
- name: SYSLIB1040-SYSLIB1049
href: ../../fundamentals/syslib-diagnostics/syslib1040-1049.md
displayProperty: syslib1041, syslib1042, syslib1043, syslib1044, syslib1045, syslib1046, syslib1047, syslib1048, syslib1049
Expand All @@ -1763,6 +1767,9 @@ items:
- name: SYSLIB1201-SYSLIB1219
href: ../../fundamentals/syslib-diagnostics/syslib1201-1219.md
displayProperty: syslib1201, syslib1202, syslib1203, syslib1204, syslib1205, syslib1206, syslib1207, syslib1208, syslib1209, syslib1210, syslib1211, syslib1212, syslib1213, syslib1214, syslib1215, syslib1216, syslib1217, syslib1218, syslib1219
- name: SYSLIB1220-SYSLIB1229
href: ../../fundamentals/syslib-diagnostics/syslib1220-1229.md
displayProperty: syslib1220, syslib1221, syslib1222, syslib1223, syslib1224, syslib1225, syslib1226, syslib1227, syslib1228, syslib1229
- name: Package validation
items:
- name: Get started
Expand Down

0 comments on commit 3b522b7

Please sign in to comment.