Copied to clipboard

Flag this post as spam?

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


  • Alessandro 11 posts 84 karma points
    Apr 03, 2019 @ 16:13
    Alessandro
    0

    Variant and contentService API

    Hi all,

    I have several problems using the ContentService to create and publish nodes programmatically in a multilanguage environment.

    Basically i have an hangfire task which periodically should sync (create, update and delete) some nodes.

    I see there's an issue about that on Github but workarounds suggested by Shazwazza don't work for me. https://github.com/umbraco/Umbraco-CMS/issues/4452

    I can only save the node while saveAndPublish throws the following error:

    System.NullReferenceException: Riferimento a un oggetto non impostato su un'istanza di oggetto.
       in Umbraco.Web.Routing.RedirectTrackingComponent.get_Moving()
       in Umbraco.Web.Routing.RedirectTrackingComponent.get_LockedEvents()
       in Umbraco.Web.Routing.RedirectTrackingComponent.ContentService_Publishing(IContentService sender, PublishEventArgs`1 args)
       in Umbraco.Core.Events.QueuingEventDispatcherBase.DispatchCancelable[TSender,TArgs](TypedEventHandler`2 eventHandler, TSender sender, TArgs args, String eventName)
       in Umbraco.Core.Services.Implement.ContentService.StrategyCanPublish(IScope scope, IContent content, Boolean checkPath, IReadOnlyList`1 culturesPublishing, IReadOnlyCollection`1 culturesUnpublishing, EventMessages evtMsgs, ContentSavingEventArgs savingEventArgs)
       in Umbraco.Core.Services.Implement.ContentService.CommitDocumentChangesInternal(IScope scope, IContent content, ContentSavingEventArgs saveEventArgs, Int32 userId, Boolean raiseEvents, Boolean branchOne, Boolean branchRoot)
       in Umbraco.Core.Services.Implement.ContentService.SaveAndPublishBranchItem(IScope scope, IContent document, Func`2 shouldPublish, Func`3 publishCultures, Boolean isRoot, ICollection`1 publishedDocuments, EventMessages evtMsgs, Int32 userId)
       in Umbraco.Core.Services.Implement.ContentService.SaveAndPublishBranch(IContent document, Boolean force, Func`2 shouldPublish, Func`3 publishCultures, Int32 userId)
       in Umbraco.Core.Services.Implement.ContentService.SaveAndPublishBranch(IContent content, Boolean force, String culture, Int32 userId)
       in MacroluxWebsite.Jobs.SyncProduct.<Execute>d__4.MoveNext() in D:\Lavori\Macrolux\MacroluxWebsite\MacroluxWebsite\Jobs\SyncProducts.cs:riga 82
    --- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
       in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       in System.Runtime.CompilerServices.TaskAwaiter.GetResult()
    

    Could be related to the backgroud job context which is missing some reference?

  • Alessandro 11 posts 84 karma points
    Apr 03, 2019 @ 16:16
    Alessandro
    0

    Furthermore, sometimes during content saving (which usually works) I see the following error thrown, related to Examine:

    System.AggregateException: Exceptions were thrown by listed actions. ---> System.ArgumentException: È già stato aggiunto un elemento con la stessa chiave.
       in System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       in System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       in Umbraco.Core.Scoping.ScopeProvider.SetCallContextObject(String key, IInstanceIdentifiable value)
       in Umbraco.Core.Scoping.ScopeProvider.SetAmbient(Scope scope, ScopeContext context)
       in Umbraco.Core.Scoping.ScopeProvider.CreateScope(IsolationLevel isolationLevel, RepositoryCacheMode repositoryCacheMode, IEventDispatcher eventDispatcher, Nullable`1 scopeFileSystems, Boolean callContext, Boolean autoComplete)
       in Umbraco.Core.Services.Implement.UserService.GetUserById(Int32 id)
       in Umbraco.Core.Services.Implement.UserService.GetProfileById(Int32 id)
       in Umbraco.Core.ContentExtensions.GetWriterProfile(IContent content, IUserService userService)
       in Umbraco.Examine.ContentValueSetBuilder.<GetValueSets>d__3.MoveNext()
       in System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
       in System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
       in System.Linq.GroupedEnumerable`3.GetEnumerator()
       in System.Linq.Buffer`1..ctor(IEnumerable`1 source)
       in System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
       in Umbraco.Examine.UmbracoContentIndex.PerformIndexItems(IEnumerable`1 values, Action`1 onComplete)
       in Examine.Providers.BaseIndexProvider.IndexItems(IEnumerable`1 values) in C:\projects\examine\src\Examine\Providers\BaseIndexProvider.cs:riga 76
       in Umbraco.Web.Search.ExamineComponent.DeferedReIndexForContent.Execute(ExamineComponent examineComponent, IContent content, Boolean isPublished)
       in Umbraco.Web.Search.ExamineComponent.DeferedReIndexForContent.Execute()
       in Umbraco.Web.Search.ExamineComponent.DeferedActions.Execute()
       in Umbraco.Web.Search.ExamineComponent.DeferedActions.<>c.<Get>b__1_1(Boolean completed, DeferedActions actions)
       in Umbraco.Core.Scoping.ScopeContext.EnlistedObject`1.Execute(Boolean completed)
       in Umbraco.Core.Scoping.ScopeContext.ScopeExit(Boolean completed)
       --- Fine della traccia dello stack dell'eccezione interna ---
       in Umbraco.Core.Scoping.ScopeContext.ScopeExit(Boolean completed)
       in Umbraco.Core.Scoping.Scope.<>c__DisplayClass72_0.<RobustExit>b__2()
       in Umbraco.Core.Scoping.Scope.TryFinally(Int32 index, Action[] actions)
       in Umbraco.Core.Scoping.Scope.TryFinally(Int32 index, Action[] actions)
       in Umbraco.Core.Scoping.Scope.TryFinally(Int32 index, Action[] actions)
       in Umbraco.Core.Scoping.Scope.RobustExit(Boolean completed, Boolean onException)
       in Umbraco.Core.Scoping.Scope.DisposeLastScope()
       in Umbraco.Core.Scoping.Scope.Dispose()
       in Umbraco.Core.Services.Implement.ContentService.Save(IContent content, Int32 userId, Boolean raiseEvents)
       in MacroluxWebsite.Jobs.SyncProduct.<Execute>d__4.MoveNext() in D:\Lavori\Macrolux\MacroluxWebsite\MacroluxWebsite\Jobs\SyncProducts.cs:riga 84
    --- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
       in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       in System.Runtime.CompilerServices.TaskAwaiter.GetResult()
    ---> (Eccezione interna 0) System.ArgumentException: È già stato aggiunto un elemento con la stessa chiave.
       in System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       in System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       in Umbraco.Core.Scoping.ScopeProvider.SetCallContextObject(String key, IInstanceIdentifiable value)
       in Umbraco.Core.Scoping.ScopeProvider.SetAmbient(Scope scope, ScopeContext context)
       in Umbraco.Core.Scoping.ScopeProvider.CreateScope(IsolationLevel isolationLevel, RepositoryCacheMode repositoryCacheMode, IEventDispatcher eventDispatcher, Nullable`1 scopeFileSystems, Boolean callContext, Boolean autoComplete)
       in Umbraco.Core.Services.Implement.UserService.GetUserById(Int32 id)
       in Umbraco.Core.Services.Implement.UserService.GetProfileById(Int32 id)
       in Umbraco.Core.ContentExtensions.GetWriterProfile(IContent content, IUserService userService)
       in Umbraco.Examine.ContentValueSetBuilder.<GetValueSets>d__3.MoveNext()
       in System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
       in System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
       in System.Linq.GroupedEnumerable`3.GetEnumerator()
       in System.Linq.Buffer`1..ctor(IEnumerable`1 source)
       in System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
       in Umbraco.Examine.UmbracoContentIndex.PerformIndexItems(IEnumerable`1 values, Action`1 onComplete)
       in Examine.Providers.BaseIndexProvider.IndexItems(IEnumerable`1 values) in C:\projects\examine\src\Examine\Providers\BaseIndexProvider.cs:riga 76
       in Umbraco.Web.Search.ExamineComponent.DeferedReIndexForContent.Execute(ExamineComponent examineComponent, IContent content, Boolean isPublished)
       in Umbraco.Web.Search.ExamineComponent.DeferedReIndexForContent.Execute()
       in Umbraco.Web.Search.ExamineComponent.DeferedActions.Execute()
       in Umbraco.Web.Search.ExamineComponent.DeferedActions.<>c.<Get>b__1_1(Boolean completed, DeferedActions actions)
       in Umbraco.Core.Scoping.ScopeContext.EnlistedObject`1.Execute(Boolean completed)
    
  • Alessandro 11 posts 84 karma points
    Apr 03, 2019 @ 16:30
    Alessandro
    0

    I can confirm that the very same code works flawlessly inside a SurfaceController Action method.

    So there's something wrong with saveAndPublish in a background job context.

    I will try with Umbraco Task Worker and report here.

  • Sean Maloney 4 posts 76 karma points
    May 08, 2019 @ 08:29
    Sean Maloney
    0

    Hi Alessandro,

    Did you ever manage to get to the bottom of this?

    I'm also trying to use Hangfire as a background task runner to import and update data using the IContentService but am getting similar errors.

    I've seen other posts related to using the UmbracoContext, but they haven't really helped.

    I managed to work around your first error by removing the Redirect Component during startup (we're not using it anyway).

    Your second error I get intermittently, presumably upon every update batch when Umbraco attempts to update the search indexes using Examine. When that error occurs I'm also seeing these entries in the log from the Scope Provider:

        Missed "ScopeContext" Object "0fd4f7c6"
    

    Presumably this is related to running in a background task rather than a web context. However I'm out of ideas at the moment!

    Thanks, Sean.

  • Mario 132 posts 826 karma points c-trib
    Oct 14, 2019 @ 22:15
    Mario
    0

    I'm having exactly this issue. Any solutions?

  • Steve Megson 150 posts 942 karma points MVP c-trib
    Oct 15, 2019 @ 09:44
    Steve Megson
    0

    The easiest workaround for the RedirectTrackingComponent error would be to disable redirect tracking with disableRedirectUrlTracking="true" in umbracosettings.config.

    If you want to keep redirect tracking enabled, there's a new version of the code coming in a future release which may work properly on background threads. It was written to fix a different problem, but it does also remove the dependency on HttpContext.Current which is causing this error. In theory it should be possible to disable the standard RedirectTrackingComponent and then include a modified version in your project.

Please Sign in or register to post replies

Write your reply to:

Draft