Runtime: System.Drawing.Primitives structs are missing TypeConverterAttribute decorations

Created on 9 Jun 2019  路  3Comments  路  Source: dotnet/runtime

Several structs in the System.Drawing.Primitives assembly are missing their TypeConverterAttribute decoration that was present in netfx. Below is a list of the structs that are missing the decoration including the converter they referenced.

|Struct|Converter|
|---|---|
|System.Drawing.Point |System.Drawing.PointConverter|
|System.Drawing.Rectangle |System.Drawing.RectangleConverter|
|System.Drawing.Size |System.Drawing.SizeConverter|
|System.Drawing.SizeF |System.Drawing.SizeFConverter|
|System.Drawing.Color |System.Drawing.ColorConverter|

This came up because PowerShell will use this attribute to determine additional conversion paths. With these attributes missing, any script that utilized these conversion paths (e.g. [System.Drawing.Point]'10,20') no longer work as expected.

Original issue: PowerShell/PowerShell#9815

area-System.Drawing

Most helpful comment

This is by design. TypeConverter is much higher in the stack in .NETCore so a lot of places that had TypeConverterAttribute in framework instead are handled intrinsically in TypeConverter itself. Powershell should not be examining metadata on types itself: just let the TypeConverter infrastructure do that. TypeDescriptor.GetConverter should tell you if a typeconverter is available, and typeconverters have CanConvert* methods that tell you if they can be used.

All 3 comments

@Anipik

I am on it

This is by design. TypeConverter is much higher in the stack in .NETCore so a lot of places that had TypeConverterAttribute in framework instead are handled intrinsically in TypeConverter itself. Powershell should not be examining metadata on types itself: just let the TypeConverter infrastructure do that. TypeDescriptor.GetConverter should tell you if a typeconverter is available, and typeconverters have CanConvert* methods that tell you if they can be used.

Was this page helpful?
0 / 5 - 0 ratings