From: Eirik Tsarpalis Date: Thu, 27 Jul 2023 12:13:27 +0000 (+0100) Subject: Ensure System.Text.Json SG diagnostics don't use Location values from referenced... X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~745 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84873e6c4e38b87185ad64beb95c6b76ec7f8d60;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Ensure System.Text.Json SG diagnostics don't use Location values from referenced assemblies. (#89518) --- diff --git a/docs/project/list-of-diagnostics.md b/docs/project/list-of-diagnostics.md index b412207..7ea3ee4 100644 --- a/docs/project/list-of-diagnostics.md +++ b/docs/project/list-of-diagnostics.md @@ -258,7 +258,7 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL | __`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`__ | *`SYSLIB1220`-`SYSLIB229` reserved for System.Text.Json.SourceGeneration.* | +| __`SYSLIB1224`__ | Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. | | __`SYSLIB1225`__ | *`SYSLIB1220`-`SYSLIB229` reserved for System.Text.Json.SourceGeneration.* | | __`SYSLIB1226`__ | *`SYSLIB1220`-`SYSLIB229` reserved for System.Text.Json.SourceGeneration.* | | __`SYSLIB1227`__ | *`SYSLIB1220`-`SYSLIB229` reserved for System.Text.Json.SourceGeneration.* | diff --git a/src/libraries/System.Text.Json/gen/Helpers/RoslynExtensions.cs b/src/libraries/System.Text.Json/gen/Helpers/RoslynExtensions.cs index 695bc01..b0cb90e 100644 --- a/src/libraries/System.Text.Json/gen/Helpers/RoslynExtensions.cs +++ b/src/libraries/System.Text.Json/gen/Helpers/RoslynExtensions.cs @@ -27,10 +27,10 @@ namespace System.Text.Json.SourceGeneration public static string GetFullyQualifiedName(this ITypeSymbol type) => type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); - public static Location? GetDiagnosticLocation(this ISymbol typeSymbol) + public static Location? GetLocation(this ISymbol typeSymbol) => typeSymbol.Locations.Length > 0 ? typeSymbol.Locations[0] : null; - public static Location? GetDiagnosticLocation(this AttributeData attributeData) + public static Location? GetLocation(this AttributeData attributeData) { SyntaxReference? reference = attributeData.ApplicationSyntaxReference; return reference?.SyntaxTree.GetLocation(reference.Span); @@ -39,9 +39,14 @@ namespace System.Text.Json.SourceGeneration /// /// Creates a copy of the Location instance that does not capture a reference to Compilation. /// - [return: NotNullIfNotNull(nameof(location))] - public static Location? GetTrimmedLocation(this Location? location) - => location is null ? null : Location.Create(location.SourceTree?.FilePath ?? "", location.SourceSpan, location.GetLineSpan().Span); + public static Location GetTrimmedLocation(this Location location) + => Location.Create(location.SourceTree?.FilePath ?? "", location.SourceSpan, location.GetLineSpan().Span); + + /// + /// Returns true if the specified location is contained in one of the syntax trees in the compilation. + /// + public static bool ContainsLocation(this Compilation compilation, Location location) + => location.SourceTree != null && compilation.ContainsSyntaxTree(location.SourceTree); /// /// Removes any type metadata that is erased at compile time, such as NRT annotations and tuple labels. diff --git a/src/libraries/System.Text.Json/gen/JsonSourceGenerator.DiagnosticDescriptors.cs b/src/libraries/System.Text.Json/gen/JsonSourceGenerator.DiagnosticDescriptors.cs index 000acd0..9f1947a 100644 --- a/src/libraries/System.Text.Json/gen/JsonSourceGenerator.DiagnosticDescriptors.cs +++ b/src/libraries/System.Text.Json/gen/JsonSourceGenerator.DiagnosticDescriptors.cs @@ -114,6 +114,14 @@ namespace System.Text.Json.SourceGeneration category: JsonConstants.SystemTextJsonSourceGenerationName, defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true); + + public static DiagnosticDescriptor JsonSerializableAttributeOnNonContextType { get; } = new DiagnosticDescriptor( + id: "SYSLIB1224", + title: new LocalizableResourceString(nameof(SR.JsonSerializableAttributeOnNonContextTypeTitle), SR.ResourceManager, typeof(FxResources.System.Text.Json.SourceGeneration.SR)), + messageFormat: new LocalizableResourceString(nameof(SR.JsonSerializableAttributeOnNonContextTypeMessageFormat), SR.ResourceManager, typeof(FxResources.System.Text.Json.SourceGeneration.SR)), + category: JsonConstants.SystemTextJsonSourceGenerationName, + defaultSeverity: DiagnosticSeverity.Warning, + isEnabledByDefault: true); } } } diff --git a/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs b/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs index 24ac7cc..3242dcc 100644 --- a/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs +++ b/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs @@ -47,9 +47,18 @@ namespace System.Text.Json.SourceGeneration #pragma warning restore public List Diagnostics { get; } = new(); + private Location? _contextClassLocation; public void ReportDiagnostic(DiagnosticDescriptor descriptor, Location? location, params object?[]? messageArgs) { + Debug.Assert(_contextClassLocation != null); + + if (location is null || !_knownSymbols.Compilation.ContainsLocation(location)) + { + // If location is null or is a location outside of the current compilation, fall back to the location of the context class. + location = _contextClassLocation; + } + Diagnostics.Add(new DiagnosticInfo { Descriptor = descriptor, @@ -82,50 +91,53 @@ namespace System.Text.Json.SourceGeneration // Ensure context-scoped metadata caches are empty. Debug.Assert(_typesToGenerate.Count == 0); Debug.Assert(_generatedTypes.Count == 0); + Debug.Assert(_contextClassLocation is null); INamedTypeSymbol? contextTypeSymbol = semanticModel.GetDeclaredSymbol(contextClassDeclaration, cancellationToken); Debug.Assert(contextTypeSymbol != null); + _contextClassLocation = contextTypeSymbol.GetLocation(); + Debug.Assert(_contextClassLocation is not null); + if (!_knownSymbols.JsonSerializerContextType.IsAssignableFrom(contextTypeSymbol)) { + ReportDiagnostic(DiagnosticDescriptors.JsonSerializableAttributeOnNonContextType, _contextClassLocation, contextTypeSymbol.ToDisplayString()); return null; } - if (!TryParseJsonSerializerContextAttributes( - contextTypeSymbol, + ParseJsonSerializerContextAttributes(contextTypeSymbol, out List? rootSerializableTypes, - out SourceGenerationOptionsSpec? options)) - { - // Context does not specify any source gen attributes. - return null; - } + out SourceGenerationOptionsSpec? options); if (rootSerializableTypes is null) { - // No types were indicated with [JsonSerializable] + // No types were annotated with JsonSerializableAttribute. + // Can only be reached if a [JsonSerializable(null)] declaration has been made. + // Do not emit a diagnostic since a NRT warning will also be emitted. return null; } + Debug.Assert(rootSerializableTypes.Count > 0); + LanguageVersion? langVersion = _knownSymbols.Compilation.GetLanguageVersion(); if (langVersion is null or < MinimumSupportedLanguageVersion) { // Unsupported lang version should be the first (and only) diagnostic emitted by the generator. - ReportDiagnostic(DiagnosticDescriptors.JsonUnsupportedLanguageVersion, contextTypeSymbol.GetDiagnosticLocation(), langVersion?.ToDisplayString(), MinimumSupportedLanguageVersion.ToDisplayString()); + ReportDiagnostic(DiagnosticDescriptors.JsonUnsupportedLanguageVersion, _contextClassLocation, langVersion?.ToDisplayString(), MinimumSupportedLanguageVersion.ToDisplayString()); return null; } - Location contextLocation = contextClassDeclaration.GetLocation(); if (!TryGetNestedTypeDeclarations(contextClassDeclaration, semanticModel, cancellationToken, out List? classDeclarationList)) { // Class or one of its containing types is not partial so we can't add to it. - ReportDiagnostic(DiagnosticDescriptors.ContextClassesMustBePartial, contextLocation, contextTypeSymbol.Name); + ReportDiagnostic(DiagnosticDescriptors.ContextClassesMustBePartial, _contextClassLocation, contextTypeSymbol.Name); return null; } // Enqueue attribute data for spec generation foreach (TypeToGenerate rootSerializableType in rootSerializableTypes) { - EnqueueType(rootSerializableType.Type, rootSerializableType.Mode, rootSerializableType.TypeInfoPropertyName, rootSerializableType.AttributeLocation); + _typesToGenerate.Enqueue(rootSerializableType); } // Walk the transitive type graph generating specs for every encountered type. @@ -135,7 +147,7 @@ namespace System.Text.Json.SourceGeneration TypeToGenerate typeToGenerate = _typesToGenerate.Dequeue(); if (!_generatedTypes.ContainsKey(typeToGenerate.Type)) { - TypeGenerationSpec spec = ParseTypeGenerationSpec(typeToGenerate, contextTypeSymbol, contextLocation, options); + TypeGenerationSpec spec = ParseTypeGenerationSpec(typeToGenerate, contextTypeSymbol, options); _generatedTypes.Add(typeToGenerate.Type, spec); } } @@ -154,6 +166,7 @@ namespace System.Text.Json.SourceGeneration // Clear the caches of generated metadata between the processing of context classes. _generatedTypes.Clear(); _typesToGenerate.Clear(); + _contextClassLocation = null; return contextGenSpec; } @@ -195,7 +208,7 @@ namespace System.Text.Json.SourceGeneration return true; } - private TypeRef EnqueueType(ITypeSymbol type, JsonSourceGenerationMode? generationMode, string? typeInfoPropertyName = null, Location? attributeLocation = null) + private TypeRef EnqueueType(ITypeSymbol type, JsonSourceGenerationMode? generationMode) { // Trim compile-time erased metadata such as tuple labels and NRT annotations. type = _knownSymbols.Compilation.EraseCompileTimeMetadata(type); @@ -209,14 +222,15 @@ namespace System.Text.Json.SourceGeneration { Type = type, Mode = generationMode, - TypeInfoPropertyName = typeInfoPropertyName, - AttributeLocation = attributeLocation, + TypeInfoPropertyName = null, + Location = type.GetLocation(), + AttributeLocation = null, }); return new TypeRef(type); } - private bool TryParseJsonSerializerContextAttributes( + private void ParseJsonSerializerContextAttributes( INamedTypeSymbol contextClassSymbol, out List? rootSerializableTypes, out SourceGenerationOptionsSpec? options) @@ -246,8 +260,6 @@ namespace System.Text.Json.SourceGeneration options = ParseJsonSourceGenerationOptionsAttribute(contextClassSymbol, attributeData); } } - - return rootSerializableTypes != null || options != null; } private SourceGenerationOptionsSpec ParseJsonSourceGenerationOptionsAttribute(INamedTypeSymbol contextType, AttributeData attributeData) @@ -399,18 +411,18 @@ namespace System.Text.Json.SourceGeneration }; } - private static TypeToGenerate? ParseJsonSerializableAttribute(AttributeData attributeData) + private TypeToGenerate? ParseJsonSerializableAttribute(AttributeData attributeData) { - ITypeSymbol? typeSymbol = null; - string? typeInfoPropertyName = null; - JsonSourceGenerationMode? generationMode = null; - Debug.Assert(attributeData.ConstructorArguments.Length == 1); - foreach (TypedConstant value in attributeData.ConstructorArguments) + var typeSymbol = (ITypeSymbol?)attributeData.ConstructorArguments[0].Value; + if (typeSymbol is null) { - typeSymbol = value.Value as ITypeSymbol; + return null; } + JsonSourceGenerationMode? generationMode = null; + string? typeInfoPropertyName = null; + foreach (KeyValuePair namedArg in attributeData.NamedArguments) { switch (namedArg.Key) @@ -426,26 +438,31 @@ namespace System.Text.Json.SourceGeneration } } - if (typeSymbol is null) + Location? location = typeSymbol.GetLocation(); + Location? attributeLocation = attributeData.GetLocation(); + Debug.Assert(attributeLocation != null); + + if (location is null || !_knownSymbols.Compilation.ContainsLocation(location)) { - return null; + // For symbols located outside the compilation, fall back to attribute location instead. + location = attributeLocation; } return new TypeToGenerate { - Type = typeSymbol, + Type = _knownSymbols.Compilation.EraseCompileTimeMetadata(typeSymbol), Mode = generationMode, TypeInfoPropertyName = typeInfoPropertyName, - AttributeLocation = attributeData.GetDiagnosticLocation(), + Location = location, + AttributeLocation = attributeLocation, }; } - private TypeGenerationSpec ParseTypeGenerationSpec(in TypeToGenerate typeToGenerate, INamedTypeSymbol contextType, Location contextLocation, SourceGenerationOptionsSpec? options) + private TypeGenerationSpec ParseTypeGenerationSpec(in TypeToGenerate typeToGenerate, INamedTypeSymbol contextType, SourceGenerationOptionsSpec? options) { Debug.Assert(IsSymbolAccessibleWithin(typeToGenerate.Type, within: contextType), "should not generate metadata for inaccessible types."); ITypeSymbol type = typeToGenerate.Type; - Location typeLocation = type.GetDiagnosticLocation() ?? typeToGenerate.AttributeLocation ?? contextLocation; ClassType classType; JsonPrimitiveTypeKind? primitiveTypeKind = GetPrimitiveTypeKind(type); @@ -465,7 +482,7 @@ namespace System.Text.Json.SourceGeneration bool implementsIJsonOnSerialized = false; bool implementsIJsonOnSerializing = false; - ProcessTypeCustomAttributes(typeToGenerate, contextType, typeLocation, + ProcessTypeCustomAttributes(typeToGenerate, contextType, out JsonNumberHandling? numberHandling, out JsonUnmappedMemberHandling? unmappedMemberHandling, out JsonObjectCreationHandling? preferredPropertyObjectCreationHandling, @@ -553,11 +570,11 @@ namespace System.Text.Json.SourceGeneration if (!TryGetDeserializationConstructor(type, useDefaultCtorInAnnotatedStructs, out IMethodSymbol? constructor)) { - ReportDiagnostic(DiagnosticDescriptors.MultipleJsonConstructorAttribute, typeLocation, type.ToDisplayString()); + ReportDiagnostic(DiagnosticDescriptors.MultipleJsonConstructorAttribute, typeToGenerate.Location, type.ToDisplayString()); } else if (constructor != null && !IsSymbolAccessibleWithin(constructor, within: contextType)) { - ReportDiagnostic(DiagnosticDescriptors.JsonConstructorInaccessible, typeLocation, type.ToDisplayString()); + ReportDiagnostic(DiagnosticDescriptors.JsonConstructorInaccessible, typeToGenerate.Location, type.ToDisplayString()); constructor = null; } @@ -567,7 +584,7 @@ namespace System.Text.Json.SourceGeneration implementsIJsonOnSerialized = _knownSymbols.IJsonOnSerializedType.IsAssignableFrom(type); ctorParamSpecs = ParseConstructorParameters(typeToGenerate, constructor, out constructionStrategy, out constructorSetsRequiredMembers); - propertySpecs = ParsePropertyGenerationSpecs(contextType, typeToGenerate, typeLocation, options, out hasExtensionDataProperty, out fastPathPropertyIndices); + propertySpecs = ParsePropertyGenerationSpecs(contextType, typeToGenerate, options, out hasExtensionDataProperty, out fastPathPropertyIndices); propertyInitializerSpecs = ParsePropertyInitializers(ctorParamSpecs, propertySpecs, constructorSetsRequiredMembers, ref constructionStrategy); } @@ -576,14 +593,14 @@ namespace System.Text.Json.SourceGeneration if (classType is ClassType.TypeUnsupportedBySourceGen) { - ReportDiagnostic(DiagnosticDescriptors.TypeNotSupported, typeToGenerate.AttributeLocation ?? typeLocation, type.ToDisplayString()); + ReportDiagnostic(DiagnosticDescriptors.TypeNotSupported, typeToGenerate.AttributeLocation ?? typeToGenerate.Location, type.ToDisplayString()); } if (!_generatedContextAndTypeNames.Add((contextType.Name, typeInfoPropertyName))) { // The context name/property name combination will result in a conflict in generated types. // Workaround for https://github.com/dotnet/roslyn/issues/54185 by keeping track of the file names we've used. - ReportDiagnostic(DiagnosticDescriptors.DuplicateTypeName, typeToGenerate.AttributeLocation ?? contextLocation, typeInfoPropertyName); + ReportDiagnostic(DiagnosticDescriptors.DuplicateTypeName, typeToGenerate.AttributeLocation ?? _contextClassLocation, typeInfoPropertyName); classType = ClassType.TypeUnsupportedBySourceGen; } @@ -621,7 +638,6 @@ namespace System.Text.Json.SourceGeneration private void ProcessTypeCustomAttributes( in TypeToGenerate typeToGenerate, INamedTypeSymbol contextType, - Location typeLocation, out JsonNumberHandling? numberHandling, out JsonUnmappedMemberHandling? unmappedMemberHandling, out JsonObjectCreationHandling? objectCreationHandling, @@ -669,7 +685,7 @@ namespace System.Text.Json.SourceGeneration if (!isPolymorphic && typeToGenerate.Mode == JsonSourceGenerationMode.Serialization) { - ReportDiagnostic(DiagnosticDescriptors.PolymorphismNotSupported, typeLocation, typeToGenerate.Type.ToDisplayString()); + ReportDiagnostic(DiagnosticDescriptors.PolymorphismNotSupported, typeToGenerate.Location, typeToGenerate.Type.ToDisplayString()); } isPolymorphic = true; @@ -845,11 +861,11 @@ namespace System.Text.Json.SourceGeneration private List ParsePropertyGenerationSpecs( INamedTypeSymbol contextType, in TypeToGenerate typeToGenerate, - Location typeLocation, SourceGenerationOptionsSpec? options, out bool hasExtensionDataProperty, out List? fastPathPropertyIndices) { + Location? typeLocation = typeToGenerate.Location; List properties = new(); PropertyHierarchyResolutionState state = new(); hasExtensionDataProperty = false; @@ -1048,7 +1064,7 @@ namespace System.Text.Json.SourceGeneration private PropertyGenerationSpec? ParsePropertyGenerationSpec( INamedTypeSymbol contextType, TypeRef declaringType, - Location typeLocation, + Location? typeLocation, ITypeSymbol memberType, ISymbol memberInfo, ref bool typeHasExtensionDataProperty, @@ -1084,7 +1100,7 @@ namespace System.Text.Json.SourceGeneration if (hasJsonIncludeButIsInaccessible) { - ReportDiagnostic(DiagnosticDescriptors.InaccessibleJsonIncludePropertiesNotSupported, memberInfo.GetDiagnosticLocation(), declaringType.Name, memberInfo.Name); + ReportDiagnostic(DiagnosticDescriptors.InaccessibleJsonIncludePropertiesNotSupported, memberInfo.GetLocation(), declaringType.Name, memberInfo.Name); } if (isExtensionData) @@ -1096,7 +1112,7 @@ namespace System.Text.Json.SourceGeneration if (!IsValidDataExtensionPropertyType(memberType)) { - ReportDiagnostic(DiagnosticDescriptors.DataExtensionPropertyInvalid, memberInfo.GetDiagnosticLocation(), declaringType.Name, memberInfo.Name); + ReportDiagnostic(DiagnosticDescriptors.DataExtensionPropertyInvalid, memberInfo.GetLocation(), declaringType.Name, memberInfo.Name); } typeHasExtensionDataProperty = true; @@ -1457,7 +1473,7 @@ namespace System.Text.Json.SourceGeneration if (!SymbolEqualityComparer.Default.Equals(attributeData.AttributeClass, _knownSymbols.JsonConverterAttributeType)) { - ReportDiagnostic(DiagnosticDescriptors.DerivedJsonConverterAttributesNotSupported, attributeData.GetDiagnosticLocation(), attributeData.AttributeClass!.ToDisplayString()); + ReportDiagnostic(DiagnosticDescriptors.DerivedJsonConverterAttributesNotSupported, attributeData.GetLocation(), attributeData.AttributeClass!.ToDisplayString()); return null; } @@ -1472,13 +1488,13 @@ namespace System.Text.Json.SourceGeneration !_knownSymbols.JsonConverterType.IsAssignableFrom(namedConverterType) || !namedConverterType.Constructors.Any(c => c.Parameters.Length == 0 && IsSymbolAccessibleWithin(c, within: contextType))) { - ReportDiagnostic(DiagnosticDescriptors.JsonConverterAttributeInvalidType, attributeData.GetDiagnosticLocation(), converterType?.ToDisplayString() ?? "null", declaringSymbol.ToDisplayString()); + ReportDiagnostic(DiagnosticDescriptors.JsonConverterAttributeInvalidType, attributeData.GetLocation(), converterType?.ToDisplayString() ?? "null", declaringSymbol.ToDisplayString()); return null; } if (_knownSymbols.JsonStringEnumConverterType.IsAssignableFrom(converterType)) { - ReportDiagnostic(DiagnosticDescriptors.JsonStringEnumConverterNotSupportedInAot, attributeData.GetDiagnosticLocation(), declaringSymbol.ToDisplayString()); + ReportDiagnostic(DiagnosticDescriptors.JsonStringEnumConverterNotSupportedInAot, attributeData.GetLocation(), declaringSymbol.ToDisplayString()); } return new TypeRef(converterType); @@ -1735,9 +1751,10 @@ namespace System.Text.Json.SourceGeneration private readonly struct TypeToGenerate { public required ITypeSymbol Type { get; init; } - public JsonSourceGenerationMode? Mode { get; init; } - public string? TypeInfoPropertyName { get; init; } - public Location? AttributeLocation { get; init; } + public required JsonSourceGenerationMode? Mode { get; init; } + public required string? TypeInfoPropertyName { get; init; } + public required Location? Location { get; init; } + public required Location? AttributeLocation { get; init; } } } } diff --git a/src/libraries/System.Text.Json/gen/Resources/Strings.resx b/src/libraries/System.Text.Json/gen/Resources/Strings.resx index 3495443..85d64b6 100644 --- a/src/libraries/System.Text.Json/gen/Resources/Strings.resx +++ b/src/libraries/System.Text.Json/gen/Resources/Strings.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. Duplicate type name. @@ -201,4 +201,10 @@ The constructor on type '{0}' has been annotated with JsonConstructorAttribute but is not accessible by the source generator. + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.cs.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.cs.xlf index 1f31e7a..167c175 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.cs.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.cs.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - Existuje několik typů s názvem {0}. Zdroj se vygeneroval pro první zjištěný typ. Tuto kolizi vyřešíte pomocí JsonSerializableAttribute.TypeInfoPropertyName. + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + Existuje několik typů s názvem {0}. Zdroj se vygeneroval pro první zjištěný typ. Tuto kolizi vyřešíte pomocí JsonSerializableAttribute.TypeInfoPropertyName. @@ -92,6 +92,16 @@ JsonConverterAttribute.Type obsahuje neplatný nebo nepřístupný argument. + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. Člen {0} byl opatřen poznámkou jsonStringEnumConverter, což není v nativním AOT podporováno. Zvažte použití obecného objektu JsonStringEnumConverter<TEnum>. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.de.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.de.xlf index 71d1d1b..013b5bd 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.de.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.de.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - Es sind mehrere Typen namens "{0}" vorhanden. Die Quelle wurde für den ersten festgestellten Typ generiert. Verwenden Sie "JsonSerializableAttribute.TypeInfoPropertyName", um diesen Konflikt zu beheben. + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + Es sind mehrere Typen namens "{0}" vorhanden. Die Quelle wurde für den ersten festgestellten Typ generiert. Verwenden Sie "JsonSerializableAttribute.TypeInfoPropertyName", um diesen Konflikt zu beheben. @@ -92,6 +92,16 @@ "JsonConverterAttribute.Type" enthält ein ungültiges oder nicht zugängliches Argument. + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. Der Member "{0}" wurde mit "JsonStringEnumConverter" kommentiert, was in nativem AOT nicht unterstützt wird. Erwägen Sie stattdessen die Verwendung des generischen "JsonStringEnumConverter<TEnum>". diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.es.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.es.xlf index 75e5520..d425fbd 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.es.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.es.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - Hay varios tipos denominados {0}. El origen se generó para el primero detectado. Use "JsonSerializableAttribute.TypeInfoPropertyName" para resolver esta colisión. + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + Hay varios tipos denominados {0}. El origen se generó para el primero detectado. Use "JsonSerializableAttribute.TypeInfoPropertyName" para resolver esta colisión. @@ -92,6 +92,16 @@ “JsonConverterAttribute.Type” contiene un argumento no válido o inaccesible. + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. El miembro '{0}' se ha anotado con 'JsonStringEnumConverter', que no se admite en AOT nativo. Considere la posibilidad de usar el elemento genérico "JsonStringEnumConverter<TEnum>" en su lugar. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.fr.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.fr.xlf index 03be4b8..0f8aeae 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.fr.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.fr.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - Plusieurs types nommés {0}. La source a été générée pour la première détection détectée. Utilisez « JsonSerializableAttribute.TypeInfoPropertyName » pour résoudre cette collision. + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + Plusieurs types nommés {0}. La source a été générée pour la première détection détectée. Utilisez « JsonSerializableAttribute.TypeInfoPropertyName » pour résoudre cette collision. @@ -92,6 +92,16 @@ 'JsonConverterAttribute.Type' contient un argument non valide ou inaccessible. + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. Le membre '{0}' a été annoté avec 'JsonStringEnumConverter', ce qui n’est pas pris en charge dans AOT natif. Utilisez plutôt le générique 'JsonStringEnumConverter<TEnum>'. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.it.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.it.xlf index b3b1d84..55f83a0 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.it.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.it.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - Sono presenti più tipi denominati {0}. L'origine è stata generata per il primo tipo rilevato. Per risolvere questa collisione, usare 'JsonSerializableAttribute.TypeInfoPropertyName'. + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + Sono presenti più tipi denominati {0}. L'origine è stata generata per il primo tipo rilevato. Per risolvere questa collisione, usare 'JsonSerializableAttribute.TypeInfoPropertyName'. @@ -92,6 +92,16 @@ 'JsonConverterAttribute.Type' contiene un argomento non valido o inaccessibile. + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. Il membro '{0}' è stato annotato con 'JsonStringEnumConverter' che non è supportato in AOT nativo. Provare a usare il generico 'JsonStringEnumConverter<TEnum>'. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ja.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ja.xlf index b50a94b..c96e927 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ja.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ja.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - {0} と名前が付けられた種類が複数あります。最初に検出されたものに対してソースが生成されました。この問題を解決するには、'JsonSerializableAttribute.TypeInfoPropertyName' を使用します。 + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + {0} と名前が付けられた種類が複数あります。最初に検出されたものに対してソースが生成されました。この問題を解決するには、'JsonSerializableAttribute.TypeInfoPropertyName' を使用します。 @@ -92,6 +92,16 @@ 'JsonConverterAttribute.Type' に無効な、またはアクセスできない引数が含まれています。 + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. メンバー '{0}' には、ネイティブ AOT ではサポートされていない 'JsonStringEnumConverter' の注釈が付けられています。 代わりに汎用の 'JsonStringEnumConverter<TEnum>' を使用することを検討してください。 diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ko.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ko.xlf index 5f90e2a..4b22d15 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ko.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ko.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - 이름이 {0}인 형식이 여러 개 있습니다. 처음 검색한 원본에 대해 원본이 생성되었습니다. 이 충돌을 해결하려면 'JsonSerializableAttribute.TypeInfoPropertyName'을 사용하세요. + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + 이름이 {0}인 형식이 여러 개 있습니다. 처음 검색한 원본에 대해 원본이 생성되었습니다. 이 충돌을 해결하려면 'JsonSerializableAttribute.TypeInfoPropertyName'을 사용하세요. @@ -92,6 +92,16 @@ 'JsonConverterAttribute.Type'에 잘못되었거나 액세스할 수 없는 인수가 포함되어 있습니다. + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. '{0}' 멤버에 네이티브 AOT에서 지원되지 않는 'JsonStringEnumConverter'로 주석이 달렸습니다. 대신 제네릭 'JsonStringEnumConverter<TEnum>'을 사용해 보세요. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pl.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pl.xlf index 70b4639..90276fa 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pl.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pl.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - Istnieje wiele typów o nazwie {0}. Wygenerowano źródło dla pierwszego wykrytego elementu. Aby rozwiązać tę kolizję, użyj „JsonSerializableAttribute. TypeInfoPropertyName”. + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + Istnieje wiele typów o nazwie {0}. Wygenerowano źródło dla pierwszego wykrytego elementu. Aby rozwiązać tę kolizję, użyj „JsonSerializableAttribute. TypeInfoPropertyName”. @@ -92,6 +92,16 @@ Typ „JsonConverterAttribute.Type” zawiera nieprawidłowy lub niedostępny argument. + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. Element członkowski '{0}' został opatrzony adnotacją 'JsonStringEnumConverter', która nie jest obsługiwana w natywnym AOT. Zamiast tego należy rozważyć użycie ogólnego konwertera „JsonStringEnumConverter<TEnum>”. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pt-BR.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pt-BR.xlf index 291c30a..4cf255e 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pt-BR.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.pt-BR.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - Existem vários tipos chamados {0}. A fonte foi gerada para o primeiro detectado. Use 'JsonSerializableAttribute.TypeInfoPropertyName' para resolver esta colisão. + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + Existem vários tipos chamados {0}. A fonte foi gerada para o primeiro detectado. Use 'JsonSerializableAttribute.TypeInfoPropertyName' para resolver esta colisão. @@ -92,6 +92,16 @@ O "JsonConverterAttribute.Type" contém um argumento inválido ou inacessível. + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. O membro "{0}" foi anotado com "JsonStringEnumConverter" que não tem suporte na AOT nativa. Considere usar o genérico "JsonStringEnumConverter<TEnum>". diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ru.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ru.xlf index 87a7936..dbfa2bd 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ru.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.ru.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - Существует несколько типов с именем {0}. Исходный код сформирован для первого обнаруженного типа. Используйте JsonSerializableAttribute.TypeInfoPropertyName для устранения этого конфликта. + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + Существует несколько типов с именем {0}. Исходный код сформирован для первого обнаруженного типа. Используйте JsonSerializableAttribute.TypeInfoPropertyName для устранения этого конфликта. @@ -92,6 +92,16 @@ Аргумент "JsonConverterAttribute.Type" содержит недопустимый или недоступный аргумент. + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. Элемент "{0}" содержит примечание JsonStringEnumConverter, что не поддерживается в собственном AOT. Вместо этого рассмотрите возможность использовать универсальный параметр JsonStringEnumConverter<TEnum>. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.tr.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.tr.xlf index 9f41469..aa2b98b 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.tr.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.tr.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - {0} adını taşıyan birden çok tür var. Kaynak, algılanan ilk tür için oluşturuldu. Bu çarpışmayı çözmek için 'JsonSerializableAttribute.TypeInfoPropertyName' özelliğini kullanın. + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + {0} adını taşıyan birden çok tür var. Kaynak, algılanan ilk tür için oluşturuldu. Bu çarpışmayı çözmek için 'JsonSerializableAttribute.TypeInfoPropertyName' özelliğini kullanın. @@ -92,6 +92,16 @@ 'JsonConverterAttribute.Type' geçersiz veya erişilemeyen bir bağımsız değişken içeriyor. + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. '{0}' adlı üyeye yerel AOT’de desteklenmeyen 'JsonStringEnumConverter' parametresi eklendi. bunun yerine genel 'JsonStringEnumConverter<TEnum>' parametresini kullanmayı deneyin. diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hans.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hans.xlf index 5a656d9..5498c96 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hans.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - 有多个名为 {0} 的类型。已为第一个检测到类型的生成源。请使用 'JsonSerializableAttribute.TypeInfoPropertyName' 以解决此冲突。 + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + 有多个名为 {0} 的类型。已为第一个检测到类型的生成源。请使用 'JsonSerializableAttribute.TypeInfoPropertyName' 以解决此冲突。 @@ -92,6 +92,16 @@ "JsonConverterAttribute.Type" 包含无效或不可访问的参数。 + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. 成员“{0}”已使用本机 AOT 中不支持的 "JsonStringEnumConverter" 进行批注。请改为考虑使用泛型 "JsonStringEnumConverter<TEnum>"。 diff --git a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hant.xlf b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hant.xlf index fa1cefb..e4652c6 100644 --- a/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/libraries/System.Text.Json/gen/Resources/xlf/Strings.zh-Hant.xlf @@ -33,8 +33,8 @@ - There are multiple types named {0}. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. - 有多個名為 {0} 的類型。已為偵測到的第一個項目產生來源。請使用 'JsonSerializableAttribute.TypeInfoPropertyName' 解決此衝突。 + There are multiple types named '{0}'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision. + 有多個名為 {0} 的類型。已為偵測到的第一個項目產生來源。請使用 'JsonSerializableAttribute.TypeInfoPropertyName' 解決此衝突。 @@ -92,6 +92,16 @@ 'JsonConverterAttribute.Type' 包含無效或無法存取的引數。 + + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + The type '{0}' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated. + + + + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + Types annotated with JsonSerializableAttribute must be classes deriving from JsonSerializerContext. + + The member '{0}' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. 成員 '{0}' 已使用原生 AOT 不支援的 'JsonStringEnumConverter' 加上標註。請考慮改用一般 'JsonStringEnumConverter<TEnum>'。 diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorDiagnosticsTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorDiagnosticsTests.cs index 4155df9..98f2b71 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorDiagnosticsTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorDiagnosticsTests.cs @@ -177,12 +177,11 @@ namespace System.Text.Json.SourceGeneration.UnitTests Compilation compilation = CompilationHelper.CreateRepeatedLocationsCompilation(); JsonSourceGeneratorResult result = CompilationHelper.RunJsonSourceGenerator(compilation, disableDiagnosticValidation: true); - INamedTypeSymbol symbol = (INamedTypeSymbol)compilation.GetSymbolsWithName("JsonContext").FirstOrDefault(); - Location location = symbol.GetAttributes()[1].GetLocation(); + Location location = compilation.GetSymbolsWithName("JsonContext").FirstOrDefault().GetAttributes()[1].GetLocation(); var expectedDiagnostics = new DiagnosticData[] { - new(DiagnosticSeverity.Warning, location, "There are multiple types named Location. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.") + new(DiagnosticSeverity.Warning, location, "There are multiple types named 'Location'. Source was generated for the first one detected. Use 'JsonSerializableAttribute.TypeInfoPropertyName' to resolve this collision.") }; CompilationHelper.AssertEqualDiagnosticMessages(expectedDiagnostics, result.Diagnostics); @@ -556,5 +555,79 @@ namespace System.Text.Json.SourceGeneration.UnitTests CompilationHelper.AssertEqualDiagnosticMessages(expectedDiagnostics, result.Diagnostics); } + + [Fact] + public void DiagnosticOnMemberFromReferencedAssembly_LocationDefaultsToContextClass() + { + Compilation referencedCompilation = CompilationHelper.CreateCompilation(""" + using System.Text.Json.Serialization; + + namespace Library + { + public class MyPoco + { + [JsonConverter(typeof(int))] + public int Value { get; set; } + } + } + """); + + // Emit the image of the referenced assembly. + byte[] referencedImage = CompilationHelper.CreateAssemblyImage(referencedCompilation); + MetadataReference[] additionalReferences = { MetadataReference.CreateFromImage(referencedImage) }; + + Compilation compilation = CompilationHelper.CreateCompilation(""" + using Library; + using System.Text.Json.Serialization; + + namespace Application + { + [JsonSerializable(typeof(MyPoco))] + public partial class MyContext : JsonSerializerContext + { } + } + """, additionalReferences); + + JsonSourceGeneratorResult result = CompilationHelper.RunJsonSourceGenerator(compilation, disableDiagnosticValidation: true); + + Location contextLocation = compilation.GetSymbolsWithName("MyContext").First().Locations[0]; + + var expectedDiagnostics = new DiagnosticData[] + { + new(DiagnosticSeverity.Warning, contextLocation, "The 'JsonConverterAttribute' type 'int' specified on member 'Library.MyPoco.Value' is not a converter type or does not contain an accessible parameterless constructor."), + }; + + CompilationHelper.AssertEqualDiagnosticMessages(expectedDiagnostics, result.Diagnostics); + } + + [Fact] + public void JsonSerializableAttributeOnNonContextClass() + { + Compilation compilation = CompilationHelper.CreateCompilation(""" + using System.Text.Json.Serialization; + + namespace Application + { + [JsonSerializable(typeof(MyPoco))] + public partial class MyContext : IDisposable + { + public void Dispose() { } + } + + public class MyPoco { } + } + """); + + JsonSourceGeneratorResult result = CompilationHelper.RunJsonSourceGenerator(compilation, disableDiagnosticValidation: true); + + Location contextLocation = compilation.GetSymbolsWithName("MyContext").First().Locations[0]; + + var expectedDiagnostics = new DiagnosticData[] + { + new(DiagnosticSeverity.Warning, contextLocation, "The type 'Application.MyContext' has been annotated with JsonSerializableAttribute but does not derive from JsonSerializerContext. No source code will be generated."), + }; + + CompilationHelper.AssertEqualDiagnosticMessages(expectedDiagnostics, result.Diagnostics); + } } } diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs index 50ee8f3..7a38a7e 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs @@ -142,6 +142,7 @@ namespace System.Text.Json.SourceGeneration.UnitTests { JsonSourceGeneratorResult result = CompilationHelper.RunJsonSourceGenerator(factory(), disableDiagnosticValidation: true); WalkObjectGraph(result.ContextGenerationSpecs); + WalkObjectGraph(result.Diagnostics); static void WalkObjectGraph(object obj) {