Skip to content

VersionConverter.ConvertTo/From may fail with Version and InstanceDescriptor types #58331

Open
@koszeggy

Description

@koszeggy

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 a Version instance that has only two or three version number elements and use destinationType: typeof(Version). The instantiation will fail because Version(int,int,int,int) constructor does not accept -1 values.
  • Call VersionConverter.ConvertFrom with an InstanceDescriptor returned by the VersionConverter.ConvertTo method from a similar Version instance.

Suggested fix

  • To convert to a Version use Version.Clone instead
  • To create an InstanceDescriptor use the string constructor or the Parse 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions