From 543e56bb06df5b2336368f0ee704d15e0ac022bd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Feb 2026 10:28:05 +0000 Subject: [PATCH 1/6] Initial plan From 2a391d0ed5082494af0b26a633a0db94caa50c5a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Feb 2026 10:30:36 +0000 Subject: [PATCH 2/6] Update SYSLIB1011 docs: generic logging methods now supported, only allows ref struct restricted Co-authored-by: svick <287848+svick@users.noreply.github.com> --- docs/core/extensions/logging/source-generation.md | 2 +- .../syslib-diagnostics/source-generator-overview.md | 2 +- docs/fundamentals/syslib-diagnostics/syslib1011.md | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/core/extensions/logging/source-generation.md b/docs/core/extensions/logging/source-generation.md index e626d01df6f47..c1edf584ec27d 100644 --- a/docs/core/extensions/logging/source-generation.md +++ b/docs/core/extensions/logging/source-generation.md @@ -119,7 +119,7 @@ Logging methods that are decorated with `LoggerMessageAttribute` must meet the f - Logging methods must be `partial` and return `void`. - Logging method names must *not* start with an underscore. - Parameter names of logging methods must *not* start with an underscore. -- Logging methods *can't* be generic. +- Logging methods support generic type parameters, but the C# 13 `allows ref struct` anti-constraint isn't supported. - If a logging method is `static`, the `ILogger` instance is required as a parameter. The code-generation model depends on code being compiled with a modern C# compiler, that is, version 9 or later. For information about changing the language version, see [C# language versioning](../../../csharp/language-reference/configure-language-version.md). diff --git a/docs/fundamentals/syslib-diagnostics/source-generator-overview.md b/docs/fundamentals/syslib-diagnostics/source-generator-overview.md index 24e8af539afe9..308a2bc7cb0cd 100644 --- a/docs/fundamentals/syslib-diagnostics/source-generator-overview.md +++ b/docs/fundamentals/syslib-diagnostics/source-generator-overview.md @@ -30,7 +30,7 @@ The following table provides an index to the `SYSLIB1XXX` diagnostics in .NET 6 | [SYSLIB1008][1008] | One of the arguments to a logging method must implement the `Microsoft.Extensions.Logging.ILogger` interface | | [SYSLIB1009][1009] | Logging methods must be `static` | | [SYSLIB1010][1010] | Logging methods must be `partial` | -| [SYSLIB1011][1011] | Logging methods cannot be generic | +| [SYSLIB1011][1011] | Logging methods cannot use the `allows ref struct` constraint | | [SYSLIB1012][1012] | Redundant qualifier in logging message | | [SYSLIB1013][1013] | Don't include exception parameters as templates in the logging message | | [SYSLIB1014][1014] | Logging template has no corresponding method argument | diff --git a/docs/fundamentals/syslib-diagnostics/syslib1011.md b/docs/fundamentals/syslib-diagnostics/syslib1011.md index 21cd44ad15f0c..69e2115d318d5 100644 --- a/docs/fundamentals/syslib-diagnostics/syslib1011.md +++ b/docs/fundamentals/syslib-diagnostics/syslib1011.md @@ -1,17 +1,17 @@ --- title: SYSLIB1011 error description: Learn about the diagnostic that generates compile-time error SYSLIB1011. -ms.date: 05/07/2021 +ms.date: 02/23/2026 f1_keywords: - syslib1011 --- -# SYSLIB1011: Logging methods cannot be generic +# SYSLIB1011: Logging methods cannot use the `allows ref struct` constraint -A method annotated with the `LoggerMessageAttribute` contains parameters with generic types. +A method annotated with `LoggerMessageAttribute` uses the C# 13 `allows ref struct` anti-constraint on a type parameter. The logging source generator stores parameters in struct fields, so it can't hold ref struct type arguments. ## Workarounds -Logging methods cannot have any generically typed parameters. Use fully resolved types instead. +Logging methods support generic type parameters and most constraint forms (`class`, `struct`, `unmanaged`, `notnull`, base types, interfaces, and `new()`). Remove the `allows ref struct` anti-constraint from the type parameter to resolve this error. [!INCLUDE [suppress-syslib-warning](includes/suppress-source-generator-diagnostics.md)] From 8f74cb4fdbbd7ce415158abcf2e556d54d01780a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 09:44:42 +0000 Subject: [PATCH 3/6] Add SYSLIB1028/1029 docs; update source-generator-overview and source-generation constraints Co-authored-by: svick <287848+svick@users.noreply.github.com> --- .../extensions/logging/source-generation.md | 1 + .../source-generator-overview.md | 6 ++++-- .../syslib-diagnostics/syslib1028.md | 17 +++++++++++++++++ .../syslib-diagnostics/syslib1029.md | 17 +++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 docs/fundamentals/syslib-diagnostics/syslib1028.md create mode 100644 docs/fundamentals/syslib-diagnostics/syslib1029.md diff --git a/docs/core/extensions/logging/source-generation.md b/docs/core/extensions/logging/source-generation.md index c1edf584ec27d..b34e671212bc1 100644 --- a/docs/core/extensions/logging/source-generation.md +++ b/docs/core/extensions/logging/source-generation.md @@ -120,6 +120,7 @@ Logging methods that are decorated with `LoggerMessageAttribute` must meet the f - Logging method names must *not* start with an underscore. - Parameter names of logging methods must *not* start with an underscore. - Logging methods support generic type parameters, but the C# 13 `allows ref struct` anti-constraint isn't supported. +- Logging method parameters can't use the `params` or `out` modifiers, and can't be ref struct types. - If a logging method is `static`, the `ILogger` instance is required as a parameter. The code-generation model depends on code being compiled with a modern C# compiler, that is, version 9 or later. For information about changing the language version, see [C# language versioning](../../../csharp/language-reference/configure-language-version.md). diff --git a/docs/fundamentals/syslib-diagnostics/source-generator-overview.md b/docs/fundamentals/syslib-diagnostics/source-generator-overview.md index 308a2bc7cb0cd..c997cc827c252 100644 --- a/docs/fundamentals/syslib-diagnostics/source-generator-overview.md +++ b/docs/fundamentals/syslib-diagnostics/source-generator-overview.md @@ -47,8 +47,8 @@ The following table provides an index to the `SYSLIB1XXX` diagnostics in .NET 6 | [SYSLIB1025][1025] | Multiple logging methods cannot use the same event name within a class | | [SYSLIB1026][1026] | C# language version not supported by the logging source generator. | | [SYSLIB1027][1027] | Primary constructor parameter of type `Microsoft.Extensions.Logging.ILogger` is hidden by a field | -| SYSLIB1028 | (Reserved for logging.) | -| SYSLIB1029 | (Reserved for logging.) | +| [SYSLIB1028][1028] | Logging method argument uses unsupported `params` parameter modifier | +| [SYSLIB1029][1029] | Logging method parameter is a ref struct | | [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 | @@ -198,6 +198,8 @@ The following table provides an index to the `SYSLIB1XXX` diagnostics in .NET 6 [1025]: syslib1025.md [1026]: syslib1026.md [1027]: syslib1027.md +[1028]: syslib1028.md +[1029]: syslib1029.md [1030]: syslib1030.md [1031]: syslib1031.md [1032]: syslib1032.md diff --git a/docs/fundamentals/syslib-diagnostics/syslib1028.md b/docs/fundamentals/syslib-diagnostics/syslib1028.md new file mode 100644 index 0000000000000..50399b178895e --- /dev/null +++ b/docs/fundamentals/syslib-diagnostics/syslib1028.md @@ -0,0 +1,17 @@ +--- +title: SYSLIB1028 error +description: Learn about the diagnostic that generates compile-time error SYSLIB1028. +ms.date: 02/25/2026 +f1_keywords: + - SYSLIB1028 +--- + +# SYSLIB1028: Argument is using the unsupported 'params' parameter modifier + +The `params` parameter modifier isn't supported for -annotated logging methods. + +## Workarounds + +Remove the `params` modifier from the parameter. + +[!INCLUDE [suppress-syslib-warning](includes/suppress-source-generator-diagnostics.md)] diff --git a/docs/fundamentals/syslib-diagnostics/syslib1029.md b/docs/fundamentals/syslib-diagnostics/syslib1029.md new file mode 100644 index 0000000000000..fe2cae737448c --- /dev/null +++ b/docs/fundamentals/syslib-diagnostics/syslib1029.md @@ -0,0 +1,17 @@ +--- +title: SYSLIB1029 error +description: Learn about the diagnostic that generates compile-time error SYSLIB1029. +ms.date: 02/25/2026 +f1_keywords: + - SYSLIB1029 +--- + +# SYSLIB1029: Logging method parameter is a ref struct + +Ref struct types aren't supported as parameters for -annotated logging methods. The logging source generator stores parameters in struct fields, which can't hold ref struct values. + +## Workarounds + +Use a non-ref struct type for the parameter. + +[!INCLUDE [suppress-syslib-warning](includes/suppress-source-generator-diagnostics.md)] From 146b97c7a7ff91e050f0c47042c8c06ea9ae5d5c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 09:52:57 +0000 Subject: [PATCH 4/6] Mention scoped modifier in SYSLIB1028 descriptions Co-authored-by: svick <287848+svick@users.noreply.github.com> --- docs/core/extensions/logging/source-generation.md | 2 +- .../syslib-diagnostics/source-generator-overview.md | 2 +- docs/fundamentals/syslib-diagnostics/syslib1028.md | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/core/extensions/logging/source-generation.md b/docs/core/extensions/logging/source-generation.md index b34e671212bc1..96cd3e2746e38 100644 --- a/docs/core/extensions/logging/source-generation.md +++ b/docs/core/extensions/logging/source-generation.md @@ -120,7 +120,7 @@ Logging methods that are decorated with `LoggerMessageAttribute` must meet the f - Logging method names must *not* start with an underscore. - Parameter names of logging methods must *not* start with an underscore. - Logging methods support generic type parameters, but the C# 13 `allows ref struct` anti-constraint isn't supported. -- Logging method parameters can't use the `params` or `out` modifiers, and can't be ref struct types. +- Logging method parameters can't use the `params`, `scoped`, or `out` modifiers, and can't be ref struct types. - If a logging method is `static`, the `ILogger` instance is required as a parameter. The code-generation model depends on code being compiled with a modern C# compiler, that is, version 9 or later. For information about changing the language version, see [C# language versioning](../../../csharp/language-reference/configure-language-version.md). diff --git a/docs/fundamentals/syslib-diagnostics/source-generator-overview.md b/docs/fundamentals/syslib-diagnostics/source-generator-overview.md index c997cc827c252..5f845de2dfee2 100644 --- a/docs/fundamentals/syslib-diagnostics/source-generator-overview.md +++ b/docs/fundamentals/syslib-diagnostics/source-generator-overview.md @@ -47,7 +47,7 @@ The following table provides an index to the `SYSLIB1XXX` diagnostics in .NET 6 | [SYSLIB1025][1025] | Multiple logging methods cannot use the same event name within a class | | [SYSLIB1026][1026] | C# language version not supported by the logging source generator. | | [SYSLIB1027][1027] | Primary constructor parameter of type `Microsoft.Extensions.Logging.ILogger` is hidden by a field | -| [SYSLIB1028][1028] | Logging method argument uses unsupported `params` parameter modifier | +| [SYSLIB1028][1028] | Logging method argument uses unsupported `params` or `scoped` parameter modifier | | [SYSLIB1029][1029] | Logging method parameter is a ref struct | | [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 | diff --git a/docs/fundamentals/syslib-diagnostics/syslib1028.md b/docs/fundamentals/syslib-diagnostics/syslib1028.md index 50399b178895e..534e7487ad991 100644 --- a/docs/fundamentals/syslib-diagnostics/syslib1028.md +++ b/docs/fundamentals/syslib-diagnostics/syslib1028.md @@ -6,12 +6,12 @@ f1_keywords: - SYSLIB1028 --- -# SYSLIB1028: Argument is using the unsupported 'params' parameter modifier +# SYSLIB1028: Argument is using an unsupported parameter modifier -The `params` parameter modifier isn't supported for -annotated logging methods. +The `params` and `scoped` parameter modifiers aren't supported for -annotated logging methods. ## Workarounds -Remove the `params` modifier from the parameter. +Remove the `params` or `scoped` modifier from the parameter. [!INCLUDE [suppress-syslib-warning](includes/suppress-source-generator-diagnostics.md)] From 2c0fe4c5d08a8f7445c0119c272ec6ba11037df7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Feb 2026 10:46:18 +0000 Subject: [PATCH 5/6] Mention ref readonly parameter support in source-generation.md Co-authored-by: svick <287848+svick@users.noreply.github.com> --- docs/core/extensions/logging/source-generation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/extensions/logging/source-generation.md b/docs/core/extensions/logging/source-generation.md index 96cd3e2746e38..e93e51b8fa457 100644 --- a/docs/core/extensions/logging/source-generation.md +++ b/docs/core/extensions/logging/source-generation.md @@ -120,7 +120,7 @@ Logging methods that are decorated with `LoggerMessageAttribute` must meet the f - Logging method names must *not* start with an underscore. - Parameter names of logging methods must *not* start with an underscore. - Logging methods support generic type parameters, but the C# 13 `allows ref struct` anti-constraint isn't supported. -- Logging method parameters can't use the `params`, `scoped`, or `out` modifiers, and can't be ref struct types. +- Logging method parameters can't use the `params`, `scoped`, or `out` modifiers, and can't be ref struct types. The `ref readonly` modifier is supported. - If a logging method is `static`, the `ILogger` instance is required as a parameter. The code-generation model depends on code being compiled with a modern C# compiler, that is, version 9 or later. For information about changing the language version, see [C# language versioning](../../../csharp/language-reference/configure-language-version.md). From 6a365f38f3e44b9e7a4d9759ef854898a8e1bcb4 Mon Sep 17 00:00:00 2001 From: Petr Onderka Date: Fri, 27 Feb 2026 11:50:18 +0100 Subject: [PATCH 6/6] Revert "Mention ref readonly parameter support in source-generation.md" This reverts commit 2c0fe4c5d08a8f7445c0119c272ec6ba11037df7. --- docs/core/extensions/logging/source-generation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/extensions/logging/source-generation.md b/docs/core/extensions/logging/source-generation.md index e93e51b8fa457..96cd3e2746e38 100644 --- a/docs/core/extensions/logging/source-generation.md +++ b/docs/core/extensions/logging/source-generation.md @@ -120,7 +120,7 @@ Logging methods that are decorated with `LoggerMessageAttribute` must meet the f - Logging method names must *not* start with an underscore. - Parameter names of logging methods must *not* start with an underscore. - Logging methods support generic type parameters, but the C# 13 `allows ref struct` anti-constraint isn't supported. -- Logging method parameters can't use the `params`, `scoped`, or `out` modifiers, and can't be ref struct types. The `ref readonly` modifier is supported. +- Logging method parameters can't use the `params`, `scoped`, or `out` modifiers, and can't be ref struct types. - If a logging method is `static`, the `ILogger` instance is required as a parameter. The code-generation model depends on code being compiled with a modern C# compiler, that is, version 9 or later. For information about changing the language version, see [C# language versioning](../../../csharp/language-reference/configure-language-version.md).