Error on using RelatedLink with Ditto and Jeavon Property Converter
public RelatedLinks RelevantLinks { get; set; }
If RelevantLinks is empty, I get this error
InvalidOperationException: {"Sequence contains no elements"}, but i want it to be empty.
It's throwing the exception when I try to store it into my Ditto model. I'm not usnig First() or FirstOrDefault() yet. I haven't begun trying to pull the data, it's erroring before I can even do that.
Are you still experiencing this issue? Which versions of Ditto and CorePropertyValueConverters are you using?
With the error message, do you get a stack-trace? If possible, could you post it here? It will help pinpoint where the issue is (either Ditto or CorePropertyValueConverters).
Someone else mentioned an issue with RelatedLinks on our Gitter chat. Jeavon was on there and said that his demo site has a working example of this, with latest Ditto.
Do you have a stack trace of the error, it'd be good to see where it's falling over.
OK, it is a bug (I think) in Ditto. Get ready for a long story...
We try to do some clever stuff when dealing with enumerables, specifically when we want to return an empty enumerable. This is where the exception happens when we try to figure out the type of enumerable:
Now the object type we're dealing with is RelatedLinks (from Jeavon's Core PropertyValueConverters project), while this appears like a concrete class, it's actually inherits from an IEnumerable<RelatedLink>.
Soooo, Ditto tries to figure out what the enumerable type is.... but it can't, since it's an inherited class. Doh!
Now here's the catch... this error only occurs if the RelatedLinks value is null. So the super-super-quick fix is populate the content for that property.
For a "proper" fix, we have a couple of options... we could ignore this and return a null or figure out how to get the inherited enumerable type. (But then this raises questions about how far down the inheritance we check - eek!)
... or an alternative is for someone (somewhere) to submit a PR to Jeavon's repo to change the converter from returning a null to returning an Enumerable.Empty<RelatedLink>?
Wow, yes, that sounds complicated! Perhaps the best option would be to do a PR... I'll look at the code you linked and see how intimidated I am by it, haha ;)
Thanks for checking into this so quickly. The navigation should never be empty, so I'll add some dummy content into it, but of course I would love to see (and help if I can!) a proper fix for the issue.
I agree! As quick note, while this doesn't fix the problem at it's root, this was a quick & dirty way for me to get around it in my project for anyone else who's wanting to use them both as well and needs a faster solution :)
/// <summary>
/// This is the main navigation that is displayed by the logo
/// </summary>
[DittoIgnore]
public RelatedLinks MainNav
{
get { return Content.GetPropertyValue<RelatedLinks>("mainNav"); }
}
I never solved this issue, but instead I decided to use NestedContent instead of RelatedLinks. Looks better to me and was a lot easier to use with Ditto.
Error on using RelatedLink with Ditto and Jeavon Property Converter
If RelevantLinks is empty, I get this error
InvalidOperationException: {"Sequence contains no elements"}, but i want it to be empty.
It's throwing the exception when I try to store it into my Ditto model. I'm not usnig First() or FirstOrDefault() yet. I haven't begun trying to pull the data, it's erroring before I can even do that.
Hi Kevin,
Are you still experiencing this issue? Which versions of Ditto and CorePropertyValueConverters are you using?
With the error message, do you get a stack-trace? If possible, could you post it here? It will help pinpoint where the issue is (either Ditto or CorePropertyValueConverters).
Thanks,
- Lee
Hi Lee!
I'm actually having this same problem. Here's the version info:
Thanks for the help! :)
Cheers, Janae
Hi Janae,
Someone else mentioned an issue with RelatedLinks on our Gitter chat. Jeavon was on there and said that his demo site has a working example of this, with latest Ditto.
Do you have a stack trace of the error, it'd be good to see where it's falling over.
Thanks, Lee
Yep, absolutely!
Here's where I'm calling it in my model:
And here's the stack strace:
Thanks Janae, hmmm, so it is Ditto! I'll take a look :-)
Thanks, Lee! I will wait with baited breath ;)
OK, it is a bug (I think) in Ditto. Get ready for a long story...
We try to do some clever stuff when dealing with enumerables, specifically when we want to return an empty enumerable. This is where the exception happens when we try to figure out the type of enumerable:
https://github.com/leekelleher/umbraco-ditto/blob/develop/src/Our.Umbraco.Ditto/ComponentModel/Processors/EnumerableConverterAttribute.cs#L76
Now the object type we're dealing with is
RelatedLinks
(from Jeavon's Core PropertyValueConverters project), while this appears like a concrete class, it's actually inherits from anIEnumerable<RelatedLink>
.https://github.com/Jeavon/Umbraco-Core-Property-Value-Converters/blob/v3/Our.Umbraco.PropertyConverters/Models/RelatedLinks.cs
Soooo, Ditto tries to figure out what the enumerable type is.... but it can't, since it's an inherited class. Doh!
Now here's the catch... this error only occurs if the
RelatedLinks
value isnull
. So the super-super-quick fix is populate the content for that property.For a "proper" fix, we have a couple of options... we could ignore this and return a
null
or figure out how to get the inherited enumerable type. (But then this raises questions about how far down the inheritance we check - eek!)... or an alternative is for someone (somewhere) to submit a PR to Jeavon's repo to change the converter from returning a
null
to returning anEnumerable.Empty<RelatedLink>
?https://github.com/Jeavon/Umbraco-Core-Property-Value-Converters/blob/v3/Our.Umbraco.PropertyConverters/RelatedLinksPropertyConverter.cs
Anyway, I'll raise this on our Ditto GitHub for review.
Cheers,
- Lee
Lee,
Wow, yes, that sounds complicated! Perhaps the best option would be to do a PR... I'll look at the code you linked and see how intimidated I am by it, haha ;)
Thanks for checking into this so quickly. The navigation should never be empty, so I'll add some dummy content into it, but of course I would love to see (and help if I can!) a proper fix for the issue.
Cheers, Janae
If it's any consolation, it's code that James South wrote, so I'm equally trying to figure out the magic of it :-)
But it's a good edge-case for Ditto that we haven't been able to replicate - until now, so all good!
I think a PR on CorePropertyValueConverters is the path of least resistance.
Cheers,
- Lee
I agree! As quick note, while this doesn't fix the problem at it's root, this was a quick & dirty way for me to get around it in my project for anyone else who's wanting to use them both as well and needs a faster solution :)
OK, you win, that's the quickest way to workaround it! :-)
I never solved this issue, but instead I decided to use NestedContent instead of RelatedLinks. Looks better to me and was a lot easier to use with Ditto.
Is it still a bug ?
Yeah, it's still an issue.
We have a failing unit-test (in a separate branch) on Ditto (PR #195), but with no current resolution (and we're not actively looking at it).
Quickest resolution is Janae's workaround... or to come up with an alternative suggestion?
Cheers,
- Lee
I've been working on a fix which passes all tests so hopefully we should have a release out very soon.
https://github.com/leekelleher/umbraco-ditto/pull/195
is working on a reply...