-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Inconsistent nullability change in TypeConverter.CanConvertTo resulting in a breaking API change with .NET 6.0 #63186
Comments
Tagging subscribers to this area: @dotnet/area-system-componentmodel Issue DetailsIn .NET 6.0, the nullability of the overload https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.typeconverter.canconvertto?view=net-6.0 https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.typeconverter.canconvertto?view=net-5.0 I believe that Note that the new API breaks existing code based on .NET 5.0 (custom TypeConverter implementations). Note that according to git, the entire nullability of TypeConverter was done with ##54961 after .NET 5.0 was already released, so I can't really backtrack this to the root cause.
|
I believe the change to cc @krwq - who made the change. Any thoughts here? |
@MichaelKetting thanks for the report, would you like to add a PR for this? |
@maryamariyan Sure thing! |
The nullability of parameter 'destinationType' in TypeConverter.CanConvertTo(...) was changed from not-nullable to nullable during the development of .NET 6. Since a destination type supported by this TypeConverter can never be null, a NotNullWhenAttribute is added to the 'destinationType' parameter when the result value of TypeConverter.CanConvertTo(...) is 'true'. Fix dotnet#63186
The nullability of parameter 'destinationType' in TypeConverter.CanConvertTo(...) was changed from not-nullable to nullable during the development of .NET 6. Since a destination type supported by this TypeConverter can never be null, a NotNullWhenAttribute is added to the 'destinationType' parameter when the result value of TypeConverter.CanConvertTo(...) is 'true'. Fix #63186
) The nullability of parameter 'destinationType' in TypeConverter.CanConvertTo(...) was changed from not-nullable to nullable during the development of .NET 6. Since a destination type supported by this TypeConverter can never be null, a NotNullWhenAttribute is added to the 'destinationType' parameter when the result value of TypeConverter.CanConvertTo(...) is 'true'. Fix dotnet/runtime#63186 Commit migrated from dotnet/runtime@ac246b1
In .NET 6.0, the nullability of the overload
TypeConverter.CanConvertTo(ITypeDescriptorContext? context, Type destinationType)
was changed. Now, thedestinationType
paramter is also nullable. The same change was not done withTypeConverter.CanConvertTo(Type destinationType)
andTypeConverter.ConvertTo
https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.typeconverter.canconvertto?view=net-6.0
public virtual bool CanConvertTo (System.ComponentModel.ITypeDescriptorContext? context, Type? destinationType);
https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.typeconverter.canconvertto?view=net-5.0
public virtual bool CanConvertTo (System.ComponentModel.ITypeDescriptorContext context, Type destinationType);
I believe that
destinationType
being nullable is an API bug introduced in .NET 6.0 since it is a) inconsistent with the remaining API, b) not documented as a use case in MSDN, and c) appears to defeat the purpose of the conversion API since you need to know the destination type in order to make an informed choice.Note that the new API breaks existing code based on .NET 5.0 (custom TypeConverter implementations).
Note that according to git, the entire nullability of TypeConverter was done with ##54961 after .NET 5.0 was already released, so I can't really backtrack this to the root cause.
The text was updated successfully, but these errors were encountered: