Copied to clipboard

Flag this post as spam?

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


  • Kristian Overgaard 22 posts 184 karma points notactivated
    Nov 06, 2019 @ 12:37
    Kristian Overgaard
    0

    Nested Content throws Empty guid. argument exception

    I'm experiencing some odd behvaiour with a doctype that has a nestedcontent property. Whenever i try to access the property it throws an Argumentexception with the message "Empty guid."

    The property has a few values set ind the backoffice:

    enter image description here I'm using modelsbuilder and is accessing the property through the generated models:

    ...
            var contentPage = Umbraco.Content(id.Value);
    
            if (contentPage == null || !(contentPage is DefaultPage))
                return (BadRequest("Unexpected nodetype"));
    
            var homepage = (DefaultPage)contentPage;
    
            if(homepage.DefaultValues != null)
            {
                foreach(var kvp in homepage.DefaultValues)
                {
                    BackendRequest.Add(kvp.Key, kvp.Value);
                }
            }
    

    I can't find any similar issues on this or other tech forums.

    Worth noting that this is happening in an API controller extending UmbracoApiController.

  • Kristian Overgaard 22 posts 184 karma points notactivated
    Nov 06, 2019 @ 13:28
    Kristian Overgaard
    1

    Figured it out now. It was because i named a property "key" on the element type used in the nested content.

    This overrides the existing key property which contains a guid.

    I renamed the properties, and it works.

  • Warren Harding 132 posts 275 karma points
    Oct 29, 2020 @ 05:53
    Warren Harding
    0

    For anyone else coming across this post - we had a similar issue and it worked out to be when pasting nested content from another nested content block.

    To resolve this, we have to past the content, then expand every nested content block to show the data that was pasted in. If we hit save and publish then it all works properly.

  • Carlos Rey 13 posts 107 karma points
    Jan 30, 2021 @ 13:05
    Carlos Rey
    2

    For anyone running into this, it looks like a bug in Umbraco when using the copy and paste funtion for content in a nested list.

    I found the easiest way to fix this is to:

    1. Create a copy of the page (right click on ... on the page in the content tree -> select "copy"). Dont select "relate to original".
    2. Delete the original page (and rename your copy to the original page name)
    3. Save and publish

    The act of creating a copy of that page seems to fix the guids in the nested list. The new copy of the page works fine.

  • danielibanez 8 posts 76 karma points
    Feb 16, 2021 @ 21:43
    danielibanez
    0

    Kristian and this comment helped me solve my issues. I originally used "key" as a property name but even after renaming I still got the "empty guid" error. Deleting the content node finally fixed everything.

  • Chris Norwood 131 posts 642 karma points
    Feb 01, 2021 @ 15:30
    Chris Norwood
    0

    We are also getting this; fortunately it's in a development environment where I'm testing, but the solutions above won't work for us as it's an automatic process that loads around 400 documents from XML.

    The process sets accordion data into Nested Content like this:

            var items = new List<Dictionary<string, object>>();
            items.Add(new Dictionary<string, object>() {
                    {
                        "ncContentTypeAlias",
                        "accordion"
                    },
                    {
                        "headerText",
                        headerText.ReplaceMany(_htmlReplacments)
                    },
                    {
                        "accordionContent",
                        cleanAccordionContent
                    }
            });
            umbracoNode.SetValue(fieldname, JsonConvert.SerializeObject(items));
    

    This used to automatically set the key value in the UmbracoPropertyData table, but now it seems that it sets a blank Guid instead - this then can't be parsed or loaded on the front end.

    I'm going to try manually inserting the key but this seems like a pretty serious bug - I will raise it with support!

  • Carlos Rey 13 posts 107 karma points
    Feb 01, 2021 @ 16:03
    Carlos Rey
    1

    Just a though : You could try something like copy & paste, but in code, during the process above ?

    // import stuff and save doc. New doc is 1592
             var documentToCopy = contentService.GetById(1592);
             var newDoc = contentService.Copy(documentToCopy, 1558, false, 0);
        // pushish newDoc
    // delete oldDoc
    

    Hacky, but might get you back up and running

  • Chris Norwood 131 posts 642 karma points
    Feb 01, 2021 @ 16:06
    Chris Norwood
    0

    It appears I can "fix" it by just adding the key to the object myself - I might need to revisit this if they fix the bug! (Also I'm making the dangerous assumption here that the Guid I generate isn't going to be used elsewhere, although I think that's fairly safe).

    Unfortunately this is only one update and there are lots, so deleting/adding new documents would generate a massive overhead - it would only be on the back office server, but it would play havoc with the process I think.

    Thanks for the thought though! :)

            items.Add(new Dictionary<string, object>() {
                    {
                        "key", 
                        $"{Guid.NewGuid()}"
                    },
                    {
                        "ncContentTypeAlias",
                        "accordion"
                    },
                    {
                        "headerText",
                        headerText.ReplaceMany(_htmlReplacments)
                    },
                    {
                        "accordionContent",
                        cleanAccordionContent
                    }
            });
    
  • Thomas 315 posts 602 karma points c-trib
    Feb 03, 2021 @ 14:54
    Thomas
    0

    Getting the same error in 8.11.1..

    Have some nested content inside a nested content that trows a "Empty guid" after I copied.

    When I open a Nested content. It opens all..

    If I copy and then delete each nested content and then insert it again then they works... ?

    Tried to open all nested and save.. Didn't do anything..

    enter image description here

  • Carlos Rey 13 posts 107 karma points
    Feb 03, 2021 @ 15:18
    Carlos Rey
    1

    Have you tried the steps above i mentioned ? Try creating a copy of the page and seeing if the copy still throws the error. Just make sure when you create the copy you unselect the "relate to original" option

  • Thomas 315 posts 602 karma points c-trib
    Feb 03, 2021 @ 15:38
    Thomas
    0

    It's on the root node, it´s a lot of sub pages that needs to be copied.. :p

    I will give it a try

  • Nora 28 posts 97 karma points
    Jul 14, 2022 @ 14:07
    Nora
    0

    We've got the same problem with copied items in nested content on an umbraco 8.7.0 installation. Does anyone know if this problem is fixed in the newer versions? Thanks a lot.

  • Carlos Rey 13 posts 107 karma points
    Jul 14, 2022 @ 15:16
    Carlos Rey
    0

    Ive not tried this in U10 (which we have just started using), but for U8, i wrote this class as a workaround that fixed the issue (Note: You will need to replace "pageModules" with the alias of the nested content field) :

    /// <summary>
    /// Seems to be a bug with copy and pasting of nested content items in Umbraco 8.5 -> 8.10.2
    /// It maybe when you copy and paste an item from a nested content tree to another nc tree, 
    /// that has a nested content prop in it with its own contents.
    /// It seems to set some guids to Guid.Empty, and this blows up the front end.
    /// 
    /// This code is to get around that by checking the page modules every time we save. 
    /// Its not pretty, but it saves me pulling out my hair.
    /// </summary>
    public class Umbraco_CopyPasteBug_Fix_Composer : ComponentComposer<Umbraco_CopyPasteBug_Fix_Component>
    { }
    
    public class Umbraco_CopyPasteBug_Fix_Component : IComponent
    {
        public void Initialize()
        {
            ContentService.Saving += this.ContentService_Saving;
        }
    
        private void ContentService_Saving(Umbraco.Core.Services.IContentService sender, Umbraco.Core.Events.ContentSavingEventArgs e)
        {
            foreach (var entity in e.SavedEntities)
            {
                foreach (var prop in entity.Properties)
                {
                    if (prop.Alias == "pageModules")
                    {
                        var val = prop.Values.FirstOrDefault();
                        if (val?.EditedValue is string)
                        {
                            string edit = val.EditedValue as string;
                            while (edit.Contains("00000000-0000-0000-0000-000000000000"))
                            {
                                edit = edit.ReplaceFirst("00000000-0000-0000-0000-000000000000", Guid.NewGuid().ToString());
                            }
                            prop.SetValue(edit);
                        }
                    }
                }
            }
        }
    
        public void Terminate()
        {
            ContentService.Saving -= ContentService_Saving;
        }
    }
    
  • Kieron McIntyre 5 posts 27 karma points
    Nov 08, 2022 @ 16:56
    Kieron McIntyre
    2

    Base on Carlos Rey's wonderful answer, here is the v10 implementation:

    public class NestedContentEmptyGuidFixComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.AddNotificationHandler<ContentSavingNotification, NestedContentEmptyGuidFixHandler>();
        }
    }
    

    and

    public class NestedContentEmptyGuidFixHandler : INotificationHandler<ContentSavingNotification>
    {
        public void Handle(ContentSavingNotification notification)
        {
            string emptyGuidString = Guid.Empty.ToString();
    
            foreach (var entity in notification.SavedEntities)
            {
                foreach (var prop in entity.Properties)
                {
                    if (prop.Alias != "pageComponents")
                        continue;
    
                    var val = prop.Values.FirstOrDefault();
                    if (val?.EditedValue is not string edit)
                        continue;
    
                    while (edit.Contains(emptyGuidString))
                    {
                        edit = edit.ReplaceFirst(emptyGuidString, Guid.NewGuid().ToString());
                    }
    
                    prop.SetValue(edit);
                }
            }
        }
    }
    
  • Ben Wilkinson 6 posts 76 karma points
    Jun 21, 2023 @ 05:33
    Ben Wilkinson
    0

    I can confirm this is still happening in v11.4.0. Thanks for you're helpful workaround/s!

Please Sign in or register to post replies

Write your reply to:

Draft