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 C# language version not supported by the logging source generator.
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 JsonSourceGenerator encountered a JsonStringEnumConverter annotation
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 JsonSourceGenerator encountered a JsonDerivedTypeAttribute annotation with JsonSourceGenerationMode.Serialization enabled
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 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.
SYSLIB1100 Configuration binding generator: Type is not supported.
SYSLIB1101 Configuration binding generator: Property on type is not supported.
SYSLIB1102 Configuration binding generator: Project's language version must be at least C# 12.
SYSLIB1103 Configuration binding generator: Value types are invalid inputs to configuration 'Bind' methods.
SYSLIB1104 Configuration binding generator: Generator cannot determine the target configuration type.
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.)
SYSLIB1201 Can't use ValidateObjectMembersAttribute or ValidateEnumeratedItemsAttribute on fields or properties with open generic types.
SYSLIB1202 A member type has no fields or properties to validate.
SYSLIB1203 A type has no fields or properties to validate.
SYSLIB1204 A type annotated with OptionsValidatorAttribute doesn't implement the necessary interface.
SYSLIB1205 A type already includes an implementation of the 'Validate' method.
SYSLIB1206 Can't validate private fields or properties.
SYSLIB1207 Member type is not enumerable.
SYSLIB1208 Validators used for transitive or enumerable validation must have a constructor with no parameters.
SYSLIB1209 OptionsValidatorAttribute can't be applied to a static class.
SYSLIB1210 Null validator type specified for the ValidateObjectMembersAttribute or ValidateEnumeratedItemsAttribute attributes.
SYSLIB1211 Unsupported circular references in model types.
SYSLIB1212 Member potentially missing transitive validation.
SYSLIB1213 Member potentially missing enumerable validation.
SYSLIB1214 Can't validate constants, static fields, or properties.
SYSLIB1215 Validation attribute on the member is inaccessible from the validator type.
SYSLIB1216 C# language version not supported by the options validation source generator.
SYSLIB1217 The validation attribute is only applicable to properties of type string, array, or ICollection; it cannot be used with other types.
SYSLIB1218 (Reserved for Microsoft.Extensions.Options.SourceGeneration.)
SYSLIB1219 (Reserved for Microsoft.Extensions.Options.SourceGeneration.)
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 Constructor annotated with JsonConstructorAttribute is inaccessible.
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.)

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>