You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Json source generator does not produce a valid diagnostic for JsonConverterAttribute subtype with no constructor parameters #88638
If using a subtype of JsonConverterAttribute which overrides the CreateConverter method but has no constructor parameters, JsonSourceGenerator.Parser.cs#L1234 produces an IndexOutOfRangeException instead of failing with an error diagnostic, which leads to errors involving unimplemented abstracts rather than expected information on the actual source of the error.
Reproduction Steps
publicclassMyJsonConverterAttribute:JsonConverterAttribute{publicoverrideJsonConverter?CreateConverter(TypetypeToConvert)=>null;// actual converter logic would go here}publicclassMyType{[MyJsonConverter]publicintFoo{get;init;}}[JsonSerializable(typeof(MyType))]publicpartialclassMyJsonContext:JsonSerializerContext;
Expected behavior
An error diagnostic on the attribute usage.
Actual behavior
Several unimplemented abstract method errors on the context class declaration and no generated code.
Regression?
No response
Known Workarounds
Using a JsonConverterFactory implementation with the default JsonConverterAttribute sidesteps the issue neatly while also just working rather than being a compiler error, but with third party libraries that may not be easy or possible.
Configuration
.net 8 preview; I do not believe it to be specific to that configuration.
Ah yes, the JsonConverterAttribute.CreateConverter method was never supported by the source generator. I think it would make sense to at least handle that case gracefully and emit a diagnostic.
Activity
eiriktsarpalis commentedon Jul 11, 2023
Ah yes, the
JsonConverterAttribute.CreateConvertermethod was never supported by the source generator. I think it would make sense to at least handle that case gracefully and emit a diagnostic.Khitiara commentedon Jul 11, 2023
Plus,
JsonConverterFactorycovers most if not all of the bases youd wantJsonConverterAttribute.CreateConverterfor anyway