umco/umbraco-tuple

Compatibility with Dropdown data type

dnwhte opened this issue ยท 5 comments

Hello,

I know this package isn't being actively developed, but I'm wondering if you could give me some direction on making it work with the built in Dropdown data type?

I am getting this error whenever a dropdown is used.

[InvalidCastException: Unable to cast object of type 'System.String' to type 'System.String[]'.]
   Umbraco.Core.PropertyEditors.ValueConverters.FlexibleDropdownPropertyValueConverter.ConvertSourceToObject(PublishedPropertyType propertyType, Object source, Boolean preview) +61
   Our.Umbraco.Tuple.ValueConverters.TupleValueConverter.ConvertSourceToObject(PublishedPropertyType propertyType, Object source, Boolean preview) +285
   Our.Umbraco.PropertyList.ValueConverters.PropertyListValueConverter.ConvertSourceToObject(PublishedPropertyType propertyType, Object source, Boolean preview) +225

Any direction would be much appreciated.

Thanks

Hi @dnwhte!

I've had a quick look at what might be happening here, and it looks that the issue might be this line...

https://github.com/umco/umbraco-tuple/blob/develop/src/Our.Umbraco.Tuple/ValueConverters/TupleValueConverter.cs#L77-L79

...where it's trying to convert the inner property value (from ConvertDataToSource) to the ClrType.

Which in the case of FlexibleDropdownPropertyValueConverter, that would be a string...

https://github.com/umbraco/Umbraco-CMS/blob/release-7.15.3/src/Umbraco.Core/PropertyEditors/ValueConverters/FlexibleDropdownPropertyValueConverter.cs#L64

...but the ConvertDataToSource method has literally just returned a string[]...

https://github.com/umbraco/Umbraco-CMS/blob/release-7.15.3/src/Umbraco.Core/PropertyEditors/ValueConverters/FlexibleDropdownPropertyValueConverter.cs#L31-L36

...so Tuple code doesn't cast/convert it to the correct type, so when the subsequent ConvertSourceToObject calls are made, it's the wrong type.

That's my (educated) guess at least - I haven't tested this out.


Are you building/running Tuple from source? Would you be willing to try out modifying these lines?

https://github.com/umco/umbraco-tuple/blob/develop/src/Our.Umbraco.Tuple/ValueConverters/TupleValueConverter.cs#L77-L79

It'd be to ignore the TryConvertTo bit and set the itemSource value directly.

e.g.

item.Value = itemSource;

๐Ÿ‘ it works!

@dnwhte Cool. (phew!) I'll close off this ticket. Feel free to send over a PR whenever you have time. ๐Ÿ‘

Will submit a PR.

Because I don't fully understand how this is working, is this a reliable solution or just a band-aid?

It's reliable, previously it was a bug. That method should return the "source" values, not the end target "object types".