Copied to clipboard

Flag this post as spam?

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


  • Giordano Polidoro 8 posts 78 karma points c-trib
    Apr 05, 2016 @ 15:17
    Giordano Polidoro
    0

    MediaService.Save gives an error, when I use a fake UmbracoContext

    Hi,

    I updated Umbraco from 7.3.7 to 7.4.2.

    I use a fake UmbracoContext to Save contents inside a System.Threading.Tasks.Task

    I followed the instructions on https://gist.github.com/sniffdk/7600822.

    var umbracoContext = ContextHelpers.EnsureUmbracoContext();
    var helper = new UmbracoHelper(umbracoContext);
    

    In this case it works:

       IMedia movie = helper.UmbracoContext.Application.Services.MediaService.GetById(id);
    

    In this case not:

     helper.UmbracoContext.Application.Services.MediaService.Save(movie);
    

    This is the exception I get:

    System.ArgumentNullException: Value cannot be null. Parameter name: httpContext at System.Web.HttpContextWrapper..ctor(HttpContext httpContext) at Umbraco.Web.SingletonHttpContextAccessor.get_Value() at Umbraco.Web.RequestLifespanMessagesFactory.Get() at Umbraco.Core.Services.MediaService.Umbraco.Core.Services.IMediaServiceOperations.Save(IMedia media, Int32 userId, Boolean raiseEvents) at Umbraco.Core.Services.MediaService.Save(IMedia media, Int32 userId, Boolean raiseEvents)

    Can anyone help me to figure it out?

    Thanks! :)

    Giordano

  • Giordano Polidoro 8 posts 78 karma points c-trib
    Apr 05, 2016 @ 15:35
    Giordano Polidoro
    0

    Maybe it depends on this: http://issues.umbraco.org/issue/U4-7577

  • Giordano Polidoro 8 posts 78 karma points c-trib
    Apr 06, 2016 @ 09:41
    Giordano Polidoro
    0

    As a fix, I overrided CreateServiceContext of WebBootManager

  • Bipin Kataria 29 posts 60 karma points
    Mar 22, 2017 @ 02:49
    Bipin Kataria
    0

    I am still unable to find the fix. Do you have code snippet which I can re-use in my custom code? I am running into same scenario where I am saving content in thread which is running in background.

Please Sign in or register to post replies

Write your reply to:

Draft