Copied to clipboard

Flag this post as spam?

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


  • Josip 195 posts 662 karma points c-trib
    Jan 26, 2023 @ 15:48
    Josip
    0

    Cannot access a disposed object.

    For some reason, I am getting the error Cannot access a disposed object. when I am trying to get the member like this: var getMember = Umbraco.Member(1234); after this line of code:

    IMedia uploadFile = Services.MediaService.CreateMediaWithIdentity(file.FileName, mediaFolderId, mediaType);
    

    But if I try to do it before, then works fine. This started to happen after Umbraco upgrade, I can't say which upgrade started causing this because I made many, but the current version is 8.18.5

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Jan 29, 2023 @ 11:26
    Marc Goodson
    0

    Hi Josip

    Where are you executing this code?

    APIController? or SurfaceController? etc

    I can't determine whether the error is with the reading of the file.FileName, eg the posted file stream has been disposed (if that is the context of uploading a file, or if it's only 'after that line' that Umbraco.Member errors? and if it's called before that line is fine?

    The error message cannot access a disposed object, is usually due to a 'scope' has become stale, which could be if this is inside a 'static' class or extension method.

    There is a discussion here: https://github.com/umbraco/Umbraco-CMS/issues/5073 that might help explain.

    If not, I'm wondering if you now need to wrap your operation inside it's own scope, hard to know without the context, but have a look at this reply on another ticket about scopes and background threads:

    https://our.umbraco.com/forum/using-umbraco-and-getting-started/102676-triggering-index-rebuild-via-hangfire-causes-objectdisposedexception-in-nucache#comment-321129

    regards

    Marc

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies