Copied to clipboard

Flag this post as spam?

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


  • Carmen 4 posts 45 karma points
    Mar 16, 2020 @ 19:06
    Carmen
    0

    "Cannot access a disposed object. Object name: 'snapshot'" when trying to get content by id

    I get this error when I try to get content by id. This is my code :

     using (var cref = _contextFactory.EnsureUmbracoContext())
            {
                var node = cref.UmbracoContext.Content.GetById(1210);
    
            }
    

    This is the stack trace:at Umbraco.Web.PublishedCache.NuCache.ContentStore.Snapshot.Get(Int32 id) in D:\a\1\s\src\Umbraco.Web\PublishedCache\NuCache\ContentStore.cs:line 1476 at Umbraco.Web.PublishedCache.NuCache.ContentCache.GetById(Boolean preview, Int32 contentId) in D:\a\1\s\src\Umbraco.Web\PublishedCache\NuCache\ContentCache.cs:line 227 at .....

    I have an IHttpModule that calls a service, and in that service I have the above lines of code.

    _contextFactory is injected in the constructor of the service.

    I am running Umbraco 8.2.1

  • Carmen 4 posts 45 karma points
    Mar 17, 2020 @ 11:39
    Carmen
    101

    What fixed it for me : My HttpModule was put after the Umbraco modules in the Web.config. After moving it above, the issue was fixed.

    The assumption is that everything is disposed of after the request goes through the Umbraco modules.

Please Sign in or register to post replies

Write your reply to:

Draft