Copied to clipboard

Flag this post as spam?

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


  • Łukasz Koruba 30 posts 151 karma points
    Nov 29, 2021 @ 10:01
    Łukasz Koruba
    0

    Error getting value from RTE with added macro in ContentPublishedNotification event

    We added simple macro for button and made it available for RTE. In the ContentPublishedNotification event we're making some custom code to push data to Redis etc and we're getting values for different properties for published content. The same code is used for returning JSON for rendering page and in event. Only in the second one it's throwing errors.

        public Dictionary<string, object> Map(IPublishedContent 
              publishedContent, GlobalSettings globalSettings)
        {
            using var context = _contextFactory.EnsureUmbracoContext();
    
            var properties = publishedContent.Properties
                .ToDictionary(x => x.Alias, x =>
                {
                    try
                    {
                        return x.GetValue();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                });
    
            foreach (var blockModuleAlias in _blockModuleAliases)
            {
                properties = _blockListMapper.Map(properties, blockModuleAlias);
            }
    
            SetBreadcrumbs(publishedContent, properties);
            SetHeaderActions(publishedContent, globalSettings, properties);
    
            return properties;
        }
    

    Unfortunatelly when we're trying to get value for RTE with macro added inside we're getting following exception. It's in the x.GetValue() method.

    enter image description here

    Stack Trace:

       at Umbraco.Cms.Web.Common.Macros.MacroRenderer.<RenderAsync>d__21.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Umbraco.Cms.Web.Common.Macros.MacroRenderer.<RenderAsync>d__20.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at Umbraco.Cms.Core.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.<>c__DisplayClass7_0.<RenderRteMacros>b__1(String macroAlias, Dictionary`2 macroAttributes)
       at Umbraco.Cms.Infrastructure.Macros.MacroTagParser.ParseMacros(String text, Action`1 textFoundCallback, Action`2 macroFoundCallback)
       at Umbraco.Cms.Core.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.RenderRteMacros(String source, Boolean preview)
       at Umbraco.Cms.Core.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.Convert(Object source, Boolean preview)
       at Umbraco.Cms.Core.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, Object inter, Boolean preview)
       at Umbraco.Cms.Core.Models.PublishedContent.PublishedPropertyType.ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, Object inter, Boolean preview)
       at Umbraco.Cms.Core.PublishedCache.PublishedElementPropertyBase.GetValue(String culture, String segment)
       at Umbraco.Extensions.PublishedPropertyExtension.Value[T](IPublishedProperty property, IPublishedValueFallback publishedValueFallback, String culture, String segment, Fallback fallback, T defaultValue)
       at Umbraco.Extensions.PublishedElementExtensions.Value[T](IPublishedElement content, IPublishedValueFallback publishedValueFallback, String alias, String culture, String segment, Fallback fallback, T defaultValue)
       at BestInvest.Common.Models.CmsModels.Generated.FullTextBlock.get_Text() in D:\__CogWorks\___Projects\BES0180-0946\src\BestInvest.Common\Models\CmsModels\Generated\FullTextBlock.generated.cs:line 58
    
  • louisjrdev 11 posts 84 karma points
    Nov 29, 2021 @ 10:49
    louisjrdev
    0

    Does x.GetValue() have an overload for passing in an IPublishedContent object? Then pass in publishedContent ?

  • Łukasz Koruba 30 posts 151 karma points
    Nov 29, 2021 @ 10:59
    Łukasz Koruba
    0

    It doesn't. It's an extension method for IPublishedContent.

Please Sign in or register to post replies

Write your reply to:

Draft