Copied to clipboard

Flag this post as spam?

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


  • Tito 314 posts 623 karma points
    Mar 06, 2020 @ 15:32
    Tito
    0

    Umbraco 8 refresh nucache broken after using media service

    I have a site (Umbraco v8.5.3) where i had to manually import products from csv using content service. After that i had to import media from a pictures folder using media service. There is something wrong because i cant get some pictures using umbraco helper and querying by id (ie. Umbraco.Media(1310)), it gets null. But i can using the content service and then if i save it i can see the picture. Or editing the item using backoffice.

    I have tried to rebuild the memory cache (from published status in settings section) but i get this error: System.NullReferenceException: Object reference not set to an instance of an object.

    First lines of stack trace:

    at Umbraco.Web.PublishedCache.NuCache.ContentStore.AddTreeNodeLocked(ContentNode content, LinkedNode1 parentLink) at Umbraco.Web.PublishedCache.NuCache.ContentStore.SetAll(IEnumerable1 kits) at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.LoadMediaFromDatabaseLocked(IScope scope, Boolean onStartup) at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.NotifyLocked(IEnumerable1 payloads, Boolean& anythingChanged) at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.Notify(JsonPayload[] payloads, Boolean& anythingChanged) at Umbraco.Web.Cache.MediaCacheRefresher.Refresh(JsonPayload[] payloads) at Umbraco.Core.Sync.ServerMessengerBase.DeliverLocal[TPayload](ICacheRefresher refresher, TPayload[] payload) at Umbraco.Core.Sync.ServerMessengerBase.Deliver[TPayload](ICacheRefresher refresher, TPayload[] payload) at Umbraco.Core.Sync.ServerMessengerBase.PerformRefresh[TPayload](ICacheRefresher refresher, TPayload[] payload) at Umbraco.Web.Cache.DistributedCache.RefreshByPayload[TPayload](Guid refresherGuid, TPayload[] payload) at Umbraco.Web.Cache.DistributedCacheExtensions.RefreshAllMediaCache(DistributedCache dc) at Umbraco.Web.Cache.DistributedCacheExtensions.RefreshAllPublishedSnapshot(DistributedCache dc) at lambdamethod(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>cDisplayClass61.

    I have tried to rebuild the database cache, it gets no error but the problem persists and after that if i try to rebuild the memory cache i get same error.

    Also, i have tried to query all media items in db and use the media service to save again using this code:

    var ms = Current.Services.MediaService;
    List<int> mediaItems;
    using (var scope = Current.ScopeProvider.CreateScope())
        {
            mediaItems = scope.Database.Query<int>("SELECT id FROM umbracoNode where nodeObjectType='B796F64C-1F99-4FFB-B886-4BF4BC011A9C'").ToList();
        }
    
    
     var mediaProblems= mediaItems.Where(it => Umbraco.Media(it) == null).ToList();
    
    foreach (var itemId in mediaProblems)
               {
    
                var obj = ms.GetById(itemId);
    
                ms.Save(obj);
    
            }
    

    After that i clean temp files from app_data and restart the app and all the pictures go back. Then if i try to reload cache problem goes back again.

    I guess at some point there was an error in the database, but how could i fix this? I dont know if it will be related to this issue, also the same project:

    https://github.com/umbraco/Umbraco-CMS/issues/7756

Please Sign in or register to post replies

Write your reply to:

Draft