Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Dec 12, 2019 @ 09:22
    Ismail Mayat
    0

    Cannot access a disposed object

    I have some code that was working with 8.00 and now i am on 8.3.0 and i am getting the following error:

    Cannot access a disposed object.\r\nObject name: 'snapshot'.","ExceptionType":"System.ObjectDisposedException","StackTrace":"
    at Umbraco.Web.PublishedCache.NuCache.ContentStore.Snapshot.Get(Int32 id) in D:\a\1\s\src\Umbraco.Web\PublishedCache\NuCache\ContentStore.cs:line 1480\r\n
    at Umbraco.Web.PublishedCache.NuCache.ContentCache.GetById(Boolean preview, Int32 contentId) in D:\a\1\s\src\Umbraco.Web\PublishedCache\NuCache\ContentCache.cs:line 226\r\n

    The code i question looks like:

    public class RedirectPublishedContentFinder : IRedirectPublishedContentFinder
    {
        private IPublishedContentCache  publishedCache { get; }
    
        public RedirectPublishedContentFinder(IPublishedContentCache publishedCache)
        {
            this.publishedCache = publishedCache;
        }
    
        public IPublishedContent Find(string url)
        {
            return publishedCache.GetByRoute(false,  new Uri(url).LocalPath.TrimEnd('/'), false);
        }
        public IPublishedContent Find(int id)
        {
            return publishedCache.GetById(false, id);
        }
        public IPublishedContent Find(Guid id)
        {
            return publishedCache.GetById(false, id);
        }
    }
    

    The error is happening on line return publishedCache.GetById(false, id);

    Looks like something with nucache?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Feb 21, 2020 @ 09:21
    Ismail Mayat
    100

    Ok thanks to callums pointer:

    bool ignoreLocalDb = Boolean.Parse(ConfigurationManager.AppSettings["ignoreLocalDb"]);
    
            //only does this for prod with slots
            if (ignoreLocalDb)
            {
                //see https://github.com/umbraco/Umbraco-CMS/issues/5035#issuecomment-523581706 
                // its a workaround for azure slot swapping, without this code you end up with
                // locks on nucache and site will not boot until u restart it after slot deploy and swap
                composition.Register(factory => new PublishedSnapshotServiceOptions
                {
                    IgnoreLocalDb = true
                });
            }
    

    See the github comment for more info

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Feb 21, 2020 @ 10:37
    Søren Gregersen
    1

    Callum would have done:

    bool.TryParse(ConfigurationManager.AppSettings["ignoreLocalDb"], out var ignoreLocalDb);
    
Please Sign in or register to post replies

Write your reply to:

Draft