Ditto doesnt play nice with RelatedLinks
BarryFogarty opened this issue Β· comments
I'm trying to cast a property As RelatedLinks (the core property) but I'm getting the following:
Can't convert IPublishedContent to Our.Umbraco.PropertyConverters.Models.RelatedLinks as it has no valid constructor. A valid constructor is either an empty one, or one accepting a single IPublishedContent parameter.
Simply using Our.Umbraco.PropertyConverter on the value works fine but when trying to pass it through a DittoValueResolver, I get the above exception. I have a simple workaround but just thought I'd let you know.
@bluefindigital Thanks for flagging it up.
The RelatedLinks
type isn't from Umbraco core, it's from @Jeavon's PropertyConverter library (ref link).
The issue is that Ditto will try to make a new instance of the RelatedLinks
object, but since the constructor requires a parameter, we have no idea what value to pass into it. If the type had an additional parameterless constructor, then it wouldn't be an issue.
// pinging @Jeavon in on this, in case he has any thoughts on the topic.
@leekelleher @bluefindigital Hmm, I guess the property is empty? I have just had a quick look at a recent project we have used RelatedLinks with Ditto
public RelatedLinks RelatedPages { get; set; }
@Jeavon Thanks for jumping in on this. Do you know if it's Ditto v0.8.0+?
@bluefindigital You mention a DittoValueResolver
, do you have a custom one? or do you mean the default (Ditto) UmbracoProperty
one?
@leekelleher ah no, it's Ditto v0.7.0, am I going to need a empty constructor for v0.8.0+?
I'll double check what we changed in v0.8.0. I vaguely recall making a decision with @mattbrailsford about constructor parameters of unknown type, that we'd throw an exception. I have a sneaky feeling that previous we were swallowing the exception. I'll check.
Otherwise, yeah, RelatedLinks
would need an empty constructor.
Ok, don't see why adding empty constructor would be a issue...?
@Jeavon Sorry, I've misread your last reply π - do you mean it's okay to add an empty constructor to RelatedLinks
or that it shouldn't need it?
Re: Ditto - I'm a bit confused with what is going on, as the difference between Ditto 0.7 and 0.8 is minimal...
0.7.0 - https://github.com/leekelleher/umbraco-ditto/blob/0.7.0/src/Our.Umbraco.Ditto/Extensions/PublishedContentExtensions.cs#L277
0.8.0 - https://github.com/leekelleher/umbraco-ditto/blob/0.8.0/src/Our.Umbraco.Ditto/Extensions/PublishedContentExtensions.cs#L277
Following the logic, then trying to map a property (of type RelatedLinks
) should have also thrown an exception with Ditto 0.7.0.
@bluefindigital Can you provide any code snippets? (Just for my sanity, more than anything else) π
@leekelleher I just tried it out and added Ditto to the UCPVC test site and it "just worked" so I'm not sure...?
@Jeavon Oooo cool! π (Thanks for testing it out)
I guess we need @bluefindigital to clarify the issue he experienced?
Sorry guys this turned out to be my mistake. I am trying out Ditflo at the moment and the problem turned out to be how I was trying to resolve a recursive property in a DittoResolver. I was ending up trying to resolve the whole IPublishedContent as RelatedLinks, not the property itself. Apologies, false alarm!
No worries @bluefindigital!
I wasn't 100% sure myself. I've added a unit-test to satisfy my curiosity π