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
Guard against invalid TypeToConvert args to read methods of object and collection converter #36605
changed the title [-]Guard against invalid TypeToConvert args to read methods for object and collection converter[/-][+]Guard against invalid TypeToConvert args to read methods of object and collection converter[/+]on May 17, 2020
Hi, @layomia So, in this should we throw an exception like stating that type mismatched or just return null?
In case of throwing an exception, what would be appropriate exception type should be thrown (InvalidOperationException?) and with which message?
@MCCshreyas I believe an InvalidOperationException with a message along the lines of "Type 'NameOfType' is not compatible with converter 'ConverterName'." is appropriate.
Closing in favor of #50205 which describes the wider problem that is at play here. TL;DR built-in object converter cannot function independently of the correct JsonTypeInfo metadata associated with the type. This would need to be fixed whenever #63791 is implemented.
Activity
[-]Guard against invalid TypeToConvert args to read methods for object and collection converter[/-][+]Guard against invalid TypeToConvert args to read methods of object and collection converter[/+]layomia commentedon Aug 27, 2020
Moving this to 6.0 since this is not a regression and will not be experienced if a compatible
typeToConvertis passed to the converter.ShreyasJejurkar commentedon Oct 8, 2020
Hi, @layomia So, in this should we throw an exception like stating that type mismatched or just return
null?In case of throwing an exception, what would be appropriate exception type should be thrown (
InvalidOperationException?) and with which message?layomia commentedon Oct 13, 2020
@MCCshreyas I believe an
InvalidOperationExceptionwith a message along the lines of"Type 'NameOfType' is not compatible with converter 'ConverterName'."is appropriate.ShreyasJejurkar commentedon Oct 14, 2020
OK @layomia, thanks for clarification! I will get that implemented!
eiriktsarpalis commentedon Apr 18, 2022
Moving to Future, as we won't have time to work on this in the .NET 7 timeframe.
Added guard to throw InvalidOperrationException.
eiriktsarpalis commentedon Dec 7, 2023
Closing in favor of #50205 which describes the wider problem that is at play here. TL;DR built-in object converter cannot function independently of the correct
JsonTypeInfometadata associated with the type. This would need to be fixed whenever #63791 is implemented.