Open
Description
Description
When I accidentally used the System.ComponentModel.VersionConverter
class in my unit tests instead of my VersionConverter
it turned out that the System implementation may fail in some cases.
Reproduction
- Call
VersionConverter.ConvertTo
with aVersion
instance that has only two or three version number elements and usedestinationType: typeof(Version)
. The instantiation will fail becauseVersion(int,int,int,int)
constructor does not accept -1 values. - Call
VersionConverter.ConvertFrom
with anInstanceDescriptor
returned by theVersionConverter.ConvertTo
method from a similarVersion
instance.
Suggested fix
- To convert to a
Version
useVersion.Clone
instead - To create an
InstanceDescriptor
use the string constructor or theParse
method instead.
Other information
I looked at the runtime unit tests and it seems that Version
and InstanceDescriptor
target types are not tested for actual conversions but only for the CanConvertTo
/CanConvertFrom
methods.