Source-generator diagnostics in .NET 6+

If your .NET 6+ project references a package that enables source generation of code, for example, a logging solution, then the analyzers that are specific to source generation will run at compile time. This article lists the compiler diagnostics related to source-generated code.

If you encounter one of these build warnings or errors, follow the specific guidance provided for the diagnostic ID listed in the Reference section. You can also suppress warnings using the specific SYSLIB1XXX diagnostic ID value. For more information, see Suppress warnings.

Analyzer warnings

The diagnostic ID values reserved for source-generated code analyzer warnings are SYSLIB1001 through SYSLIB1999.

Reference

The following table provides an index to the SYSLIB1XXX diagnostics in .NET 6 and later versions.

Diagnostic ID Description
SYSLIB1001 Logging method names cannot start with _
SYSLIB1002 Don't include log level parameters as templates in the logging message
SYSLIB1003 InvalidLoggingMethodParameterNameTitle
SYSLIB1004 Logging class cannot be in nested types.
SYSLIB1005 Could not find a required type definition
SYSLIB1006 Multiple logging methods cannot use the same event ID within a class
SYSLIB1007 Logging methods must return void
SYSLIB1008 One of the arguments to a logging method must implement the Microsoft.Extensions.Logging.ILogger interface
SYSLIB1009 Logging methods must be static
SYSLIB1010 Logging methods must be partial
SYSLIB1011 Logging methods cannot be generic
SYSLIB1012 Redundant qualifier in logging message
SYSLIB1013 Don't include exception parameters as templates in the logging message
SYSLIB1014 Logging template has no corresponding method argument
SYSLIB1015 Argument is not referenced from the logging message
SYSLIB1016 Logging methods cannot have a body
SYSLIB1017 A LogLevel value must be supplied in the LoggerMessage attribute or as a parameter to the logging method
SYSLIB1018 Don't include logger parameters as templates in the logging message
SYSLIB1019 Couldn't find a field of type Microsoft.Extensions.Logging.ILogger
SYSLIB1020 Found multiple fields of type Microsoft.Extensions.Logging.ILogger
SYSLIB1021 Multiple message-template item names differ only by case
SYSLIB1022 Can't have malformed format strings (for example, dangling curly braces)
SYSLIB1023 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.)
SYSLIB1027 (Reserved for logging.)
SYSLIB1028 (Reserved for logging.)
SYSLIB1029 (Reserved for logging.)
SYSLIB1030 The System.Text.Json source generator did not generate serialization metadata for type
SYSLIB1031 The System.Text.Json source generator encountered a duplicate JsonTypeInfo property name
SYSLIB1032 The System.Text.Json source generator encountered a context class that is not partial
SYSLIB1033 The System.Text.Json source generator encountered a type that has multiple [JsonConstructor] annotations
SYSLIB1034 (Reserved for System.Text.Json.SourceGeneration.)
SYSLIB1035 The System.Text.Json source generator encountered a type that has multiple [JsonExtensionData] annotations
SYSLIB1036 The System.Text.Json source generator encountered an invalid [JsonExtensionData] annotation
SYSLIB1037 The System.Text.Json source generator encountered a type with init-only properties for which deserialization is not supported
SYSLIB1038 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.)
SYSLIB1040 Invalid GeneratedRegexAttribute usage.
SYSLIB1041 Multiple GeneratedRegexAttribute attributes were applied to the same method, but only one is allowed.
SYSLIB1042 The specified regular expression is invalid.
SYSLIB1043 A GeneratedRegexAttribute method must be partial, parameterless, non-generic, and non-abstract, and return Regex.
SYSLIB1044 The regex generator couldn't generate a complete source implementation for the specified regular expression due to an internal limitation. See the explanation in the generated source for more details.
SYSLIB1045 Use GeneratedRegexAttribute to generate the regular expression implementation at compile time.
SYSLIB1046 (Reserved for System.Text.RegularExpressions.Generator.)
SYSLIB1047 (Reserved for System.Text.RegularExpressions.Generator.)
SYSLIB1048 (Reserved for System.Text.RegularExpressions.Generator.)
SYSLIB1049 (Reserved for System.Text.RegularExpressions.Generator.)
SYSLIB1050 Invalid LibraryImportAttribute usage.
SYSLIB1051 The specified type is not supported by source-generated p/invokes.
SYSLIB1052 The specified configuration is not supported by source-generated p/invokes.
SYSLIB1053 The specified LibraryImportAttribute arguments cannot be forwarded to DllImportAttribute.
SYSLIB1054 Use LibraryImportAttribute instead of DllImportAttribute to generate p/invoke marshalling code at compile time.
SYSLIB1055 Invalid CustomMarshallerAttribute usage.
SYSLIB1056 The specified native type is invalid.
SYSLIB1057 The marshaller type does not have the required shape.
SYSLIB1058 Invalid NativeMarshallingAttribute usage.
SYSLIB1059 The marshaller type does not support an allocating constructor.
SYSLIB1060 The specified marshaller type is invalid.
SYSLIB1061 The marshaller type has incompatible method signatures.
SYSLIB1062 The project must be updated with <AllowUnsafeBlocks>true</AllowUnsafeBlocks>.
SYSLIB1063 (Reserved for Microsoft.Interop.LibraryImportGenerator.)
SYSLIB1064 (Reserved for Microsoft.Interop.LibraryImportGenerator.)
SYSLIB1065 (Reserved for Microsoft.Interop.LibraryImportGenerator.)
SYSLIB1066 (Reserved for Microsoft.Interop.LibraryImportGenerator.)
SYSLIB1067 (Reserved for Microsoft.Interop.LibraryImportGenerator.)
SYSLIB1068 (Reserved for Microsoft.Interop.LibraryImportGenerator.)
SYSLIB1069 (Reserved for Microsoft.Interop.LibraryImportGenerator.)
SYSLIB1070 Invalid JSImportAttribute usage.
SYSLIB1071 Invalid JSExportAttribute usage.
SYSLIB1072 The specified type is not supported by source-generated JavaScript interop.
SYSLIB1073 The specified configuration is not supported by source-generated JavaScript interop.
SYSLIB1074 JSImportAttribute requires unsafe code.
SYSLIB1075 JSImportAttribute requires unsafe code.
SYSLIB1076 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1077 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1078 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1079 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1080 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1081 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1082 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1083 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1084 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1085 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1086 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1087 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1088 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1089 (Reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator.)
SYSLIB1090 Invalid GeneratedComInterfaceAttribute usage.
SYSLIB1091 Method is declared in different partial declaration than the GeneratedComInterface attribute.
SYSLIB1092 (Reserved for Microsoft.Interop.ComInteropGenerator.)
SYSLIB1093 (Reserved for Microsoft.Interop.ComInteropGenerator.)
SYSLIB1094 (Reserved for Microsoft.Interop.ComInteropGenerator.)
SYSLIB1095 (Reserved for Microsoft.Interop.ComInteropGenerator.)
SYSLIB1096 (Reserved for Microsoft.Interop.ComInteropGenerator.)
SYSLIB1097 (Reserved for Microsoft.Interop.ComInteropGenerator.)
SYSLIB1098 (Reserved for Microsoft.Interop.ComInteropGenerator.)
SYSLIB1099 (Reserved for Microsoft.Interop.ComInteropGenerator.)
SYSLIB1100 Type is not supported.
SYSLIB1101 Property on type is not supported.
SYSLIB1102 Project's language version must be at least C# 11.
SYSLIB1103 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1104 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1105 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1106 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)(Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1107 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1108 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1109 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1110 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1111 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1112 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1113 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1114 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1115 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1116 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1117 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)
SYSLIB1118 (Reserved for Microsoft.Extensions.Configuration.Binder.SourceGeneration.)

Suppress warnings

It's recommended that you use one of the workarounds when possible. However, if you cannot change your code, you can suppress the warning through a #pragma directive or a <NoWarn> project setting. If the SYSLIB1XXX source generator diagnostic doesn't surface as an error, you can suppress the warning in code or in your project file.

To suppress the warnings in code:

// Disable the warning.
#pragma warning disable SYSLIB1006

// Code that generates compiler diagnostic.
// ...

// Re-enable the warning.
#pragma warning restore SYSLIB1006

To suppress the warnings in a project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
   <TargetFramework>net6.0</TargetFramework>
   <!-- NoWarn below suppresses SYSLIB1002 project-wide -->
   <NoWarn>$(NoWarn);SYSLIB1002</NoWarn>
   <!-- To suppress multiple warnings, you can use multiple NoWarn elements -->
   <NoWarn>$(NoWarn);SYSLIB1002</NoWarn>
   <NoWarn>$(NoWarn);SYSLIB1006</NoWarn>
   <!-- Alternatively, you can suppress multiple warnings by using a semicolon-delimited list -->
   <NoWarn>$(NoWarn);SYSLIB1002;SYSLIB1006;SYSLIB1007</NoWarn>
  </PropertyGroup>
</Project>