MS doing the wrong thing because of the wrong backwards compatibility reasons (TypeConverter.IsValid story)
About a year ago (feb-22-2005) I reported a bug in the implementation of most built-in TypeConverters, which is that even if the value you pass to IsValid
is invalid for the target type, it will return true. To better understand the issue (which is fairly trivial anyway), say you have code like the following that performs validation on a property value before setting it:
object theObject; // Received somehow
object theValue; // Received somehow
PropertyInfo property; // Get the property info using reflection for the property we're about to set.
TypeConverter converter = TypeDescriptor.GetConverter(property.PropertyType);
if (!converter.IsValid(theValue))
{
throw new ArgumentException();
}
else
{
property.SetValue(theObject, theValue, null);
}
Now, because of the bug I mentioned, the if will never enter as the built-in converters will always report a valid value even if you pass an "asdf" for an integer property, for example. So, obviously my code has a bug that I still didn't realize (assuming I didn't do any TDD, of course, as otherwise I'd already know there's no way that code would work as expected).
Someone on the .NET team decided that it was going to be a breaking change to fix it. In their words, two months after I reported the bug, they said:
"Since TypeConverters are used so widely, changing the Int32Converter (and the other TypeConverters mentioned) to override IsValid will likely break applications, ..."
Now, how can an application be broken if a piece of functionality is not usable because it never behaves as expected? Clearly the application is already broken (if it uses code like the one I showed above) and probably the developers didn't realize yet.
After I reopened the bug so that it gets considered for post-Whidbey, I got the following answer:
"We do not have the luxury of making that risky assumption that people will not be affected by the potential change."
And closed as won't fix. I think this is a clear case where the back-compat issue is taken too far and clearly hinders the usability and quality of the platform.
If you agree, go vote the bug. The .NET platform CAN be better.