Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevin Duong 15 posts 85 karma points
    Aug 11, 2016 @ 13:22
    Kevin Duong
    0

    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.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Aug 18, 2016 @ 15:41
    Lee Kelleher
    0

    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

  • Janae Cram 63 posts 439 karma points MVP 7x c-trib
    Oct 11, 2016 @ 18:53
    Janae Cram
    0

    Hi Lee!

    I'm actually having this same problem. Here's the version info:

    • Ditto: 0.10.0
    • CorePropertyValueConverters: 3.1.1

    Thanks for the help! :)

    Cheers, Janae

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Oct 11, 2016 @ 18:58
    Lee Kelleher
    0

    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

  • Janae Cram 63 posts 439 karma points MVP 7x c-trib
    Oct 11, 2016 @ 19:08
    Janae Cram
    0

    Yep, absolutely!

    Here's where I'm calling it in my model:

        /// <summary>
        /// This is the main navigation that is displayed by the logo
        /// </summary>
        public RelatedLinks MainNav { get; set; }
    

    And here's the stack strace:

    [InvalidOperationException: Sequence contains no elements]
       System.Linq.Enumerable.First(IEnumerable`1 source) +415
       Our.Umbraco.Ditto.EnumerableConverterAttribute.ProcessValue() +457
       Our.Umbraco.Ditto.DittoCacheableAttribute.GetCacheItem(DittoCacheContext cacheContext, Func`1 refresher) +121
       Our.Umbraco.Ditto.PublishedContentExtensions.DoGetProcessedValue(IPublishedContent content, CultureInfo culture, Type targetType, PropertyInfo propertyInfo, PropertyDescriptor propertyDescriptor, Type defaultProcessorType, IEnumerable`1 processorContexts) +1276
       Our.Umbraco.Ditto.PublishedContentExtensions.GetProcessedValue(IPublishedContent content, CultureInfo culture, Type targetType, PropertyInfo propertyInfo, Object instance, Type defaultProcessorType, IEnumerable`1 processorContexts) +685
       Our.Umbraco.Ditto.PublishedContentExtensions.ConvertContent(IPublishedContent content, Type type, CultureInfo culture, Object instance, IEnumerable`1 processorContexts, Action`1 onConverting, Action`1 onConverted) +2565
       Our.Umbraco.Ditto.PublishedContentExtensions.As(IPublishedContent content, Type type, CultureInfo culture, Object instance, IEnumerable`1 processorContexts, Action`1 onConverting, Action`1 onConverted) +706
       Our.Umbraco.Ditto.PublishedContentExtensions.As(IPublishedContent content, CultureInfo culture, T instance, IEnumerable`1 processorContexts, Action`1 onConverting, Action`1 onConverted) +110
       Olympic.Web.Controllers.BaseSurfaceController`1.Index(RenderModel model) +202
       lambda_method(Closure , ControllerBase , Object[] ) +94
       System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +229
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
       System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39
       System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +71
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +72
       System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +386
       System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +386
       System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +386
       System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +386
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +38
       System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +186
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
       System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
       System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157
    
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Oct 11, 2016 @ 19:21
    Lee Kelleher
    0

    Thanks Janae, hmmm, so it is Ditto! I'll take a look :-)

  • Janae Cram 63 posts 439 karma points MVP 7x c-trib
    Oct 11, 2016 @ 19:28
    Janae Cram
    0

    Thanks, Lee! I will wait with baited breath ;)

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Oct 11, 2016 @ 19:52
    Lee Kelleher
    1

    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 an IEnumerable<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 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>?

    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

  • Janae Cram 63 posts 439 karma points MVP 7x c-trib
    Oct 11, 2016 @ 19:56
    Janae Cram
    0

    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

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Oct 11, 2016 @ 20:00
    Lee Kelleher
    0

    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

  • Janae Cram 63 posts 439 karma points MVP 7x c-trib
    Oct 11, 2016 @ 20:07
    Janae Cram
    0

    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"); }
    }
    
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Oct 12, 2016 @ 08:55
    Lee Kelleher
    0

    OK, you win, that's the quickest way to workaround it! :-)

  • Kevin Duong 15 posts 85 karma points
    Oct 11, 2016 @ 19:40
    Kevin Duong
    0

    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.

  • Norbert Haberl 32 posts 115 karma points
    Nov 09, 2016 @ 11:17
    Norbert Haberl
    0

    Is it still a bug ?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 09, 2016 @ 11:30
    Lee Kelleher
    0

    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

  • James Jackson-South 489 posts 1747 karma points c-trib
    Nov 23, 2016 @ 15:14
    James Jackson-South
    1

    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

Please Sign in or register to post replies

Write your reply to:

Draft