Description
Take this class
[JsonSerializable(typeof(IDictionary<string,object?>))]publicpartialclassJsonContextTest:JsonSerializerContext{}When used like this:
IDictionary<string,object?>d=newDictionary<string,object?>(){["A"]="b",["D"]=1,["C"]=null};varb=JsonContent.Create(d,JsonContextTest.Default.IDictionaryStringObject);It raises CS8620 Argument of type 'System.Collections.Generic.IDictionary<string,object?>' cannot be used for parameter 'inputValue' of type 'System.Collections.Generic.IDictionary<string,object>?' in 'System.Net.Http.Json.JsonContent.Create<T>' because of differences in the nullability of reference types
Generated code for JsonContextTest:
publicglobal::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.Collections.Generic.IDictionary<string,object>>IDictionaryStringObject
Notice the absence of object?
It does not raise any runtime errors however when using
My colleague is treating all warnings as errors so is there any way to avoid raising CS8620 besides NoWarn?
Reproduction Steps
Create class
[JsonSerializable(typeof(IDictionary<string,object?>))]publicpartialclassJsonContextTest:JsonSerializerContext{}Use it
IDictionary<string,object?>d=newDictionary<string,object?>(){["A"]="b",["D"]=1,["C"]=null};varb=JsonContent.Create(d,JsonContextTest.Default.IDictionaryStringObject);Expected behavior
No warning raised
Actual behavior
CS8620 is raised
Regression?
No response
Known Workarounds
No response
Configuration
.NET 8
Other information
No response
Description
Take this class
When used like this:
It raises CS8620
Argument of type 'System.Collections.Generic.IDictionary<string,object?>' cannot be used for parameter 'inputValue' of type 'System.Collections.Generic.IDictionary<string,object>?' in 'System.Net.Http.Json.JsonContent.Create<T>' because of differences in the nullability of reference typesGenerated code for JsonContextTest:
Notice the absence of
object?It does not raise any runtime errors however when using
My colleague is treating all warnings as errors so is there any way to avoid raising CS8620 besides
NoWarn?Reproduction Steps
Create class
Use it
Expected behavior
No warning raised
Actual behavior
CS8620 is raised
Regression?
No response
Known Workarounds
No response
Configuration
.NET 8
Other information
No response