-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CS8631 in System.Text.Json source generated code #78903
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsDescriptionSimple program produces warning/error (depends on TreatWarningsAsErrors switch) when using System.Text.Json source generator Reproduction StepsRepro <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LangVersion>latest</LangVersion>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project> using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
namespace A;
[JsonSerializable(typeof(Class1))]
internal partial class MyJsonContext : JsonSerializerContext
{
}
public class Class1
{
public Class2? Property { get; set; }
}
public class Class2 : ReadOnlyDictionary<string, object?>
{
public Class2(IDictionary<string, object?> dictionary)
: base(dictionary)
{
}
} Expected behaviorNo warning/error. Actual behaviorError CS8631 The type 'A.Class2' cannot be used as type parameter 'TCollection' in the generic type or method 'JsonMetadataServices.CreateIDictionaryInfo<TCollection, TKey, TValue>(JsonSerializerOptions, JsonCollectionInfoValues)'. Nullability of type argument 'A.Class2' doesn't match constraint type 'System.Collections.Generic.IDictionary<string, object>'. Regression?No response Known WorkaroundsNo response Configuration
Other informationNo response
|
Duplicate of #61734. Incidentally we've disabled nullability warnings in .NET 7 so upgrading to the latest STJ version should make the issue go away. |
Description
Simple program produces warning/error (depends on TreatWarningsAsErrors switch) when using System.Text.Json source generator
Reproduction Steps
Repro
Expected behavior
No warning/error.
Actual behavior
Error CS8631 The type 'A.Class2' cannot be used as type parameter 'TCollection' in the generic type or method 'JsonMetadataServices.CreateIDictionaryInfo<TCollection, TKey, TValue>(JsonSerializerOptions, JsonCollectionInfoValues)'. Nullability of type argument 'A.Class2' doesn't match constraint type 'System.Collections.Generic.IDictionary<string, object>'.
Regression?
No response
Known Workarounds
No response
Configuration
Other information
No response
The text was updated successfully, but these errors were encountered: