Copied to clipboard

Flag this post as spam?

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


  • Edmond 1 post 71 karma points
    Apr 24, 2019 @ 11:27
    Edmond
    0

    Nested Content

    We use the code below to get NestedContent, on v7 was working fine, but when we tried to migrate to v8 and changed the IPublishedContent with IPublishedElement, we get an error:

    System.MissingMethodException: 'Constructor on type 'Models.Fields.Section' not found.

     protected List<T> GetNestedList<T>(string alias)
        {
            Type type = typeof(T);
            List<T> list = new List<T>();
    
            IPublishedElement singleResult = Get<IPublishedElement>(alias);
    
            if (singleResult != null)
            {
                list.Add((T)Activator.CreateInstance(type, singleResult));
            }
    
            IEnumerable<IPublishedElement> multipleResults = Get<IEnumerable<IPublishedElement>>(alias);
    
            if (multipleResults != null)
            {
                foreach (IPublishedElement result in multipleResults)
                {
                    list.Add((T)Activator.CreateInstance(type, result));
                }
            }
    
            return list;
     }
    

    The only change we did to the code was replacing IPublishedContent -> IPublishedElement.

    We really need help on this.

  • Thomsen 112 posts 335 karma points
    Apr 24, 2019 @ 20:34
    Thomsen
    0

    Maybe a stupid question, but what does "Get" refer to? In fx

    Get<IPublishedElement>(alias); 
    

    is that a wrapper or helper you have defined another place?

    Best regards.

Please Sign in or register to post replies

Write your reply to:

Draft