Copied to clipboard

Flag this post as spam?

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

  • Karl 13 posts 126 karma points
    Jul 08, 2014 @ 11:43

    Media service SetValue Problem

    I am getting System.ArgumentOutOfRangeException exception when trying to setvalue from a stream

    Length cannot be less than zero. Parameter name: length


    public HttpResponseMessage CreateMedia()
    var mediaService = Services.MediaService;
    using (WebClient client = new WebClient())
    Stream s = client.OpenRead(" 1b346a5f9b2e.jpg");
    using (MemoryStream ms = new MemoryStream())
    var mediaImage = mediaService.CreateMedia("test4", 1152, "Image");
    mediaImage.SetValue("umbracoFile", "test4", ms);

    var response = Request.CreateResponse(HttpStatusCode.OK);
    response.Content = new StringContent("ExternalMediaCreate", Encoding.UTF8, "application/json");
    return response;

    Any help would be appreciated. Thanks

  • Charles Afford 1163 posts 1709 karma points
    Jul 08, 2014 @ 19:37
    Charles Afford

    Hi what parameters does SetValue() have?  Have you got the right parameter list?  I cannot remember how i have done this pof the top of my head, but have had the same problem.  Does ms have a length > 0?

    Charlie :)

  • Karl 13 posts 126 karma points
    Jul 09, 2014 @ 10:58

    Hi Charlie

    Thanks for the reply :)

    SetValue accepts the following (string propertyTypeAlias, string filename, Stream fileStream)

    Length of ms is > 0

    The propblem is I have an external mvc project which acts as a media library, I have a facilty where the user can crop and optimise the image and then be able to send the image to our main website.

    So I would like to pass a reference to the image to the main website api to index the media within umbraco.


  • Karl 13 posts 126 karma points
    Jul 09, 2014 @ 17:33

    Found out the cause of the issue,

    I changed the memorystream into a filestream so I could access the name.

    Set the name as a parameter on the setvalue, and it works :)


                var mediaService = Services.MediaService;
                var request = WebRequest.Create("");
                var webResponse = request.GetResponse();
                var responseStream = webResponse.GetResponseStream();
                if (responseStream != null)
                    var originalImage = new Bitmap(responseStream);
                    var path = HttpContext.Current.Server.MapPath("~/_tmp/ef093845-41dd-4620-b220-1b346a5f9b2e.jpg");
                    originalImage.Save(path, ImageFormat.Jpeg);
                    FileStream fileStream = new FileStream(path, FileMode.Open);
                    var test = fileStream.Name;
                    var mediaImage = mediaService.CreateMedia("test4", 1152, "Image");
                    mediaImage.SetValue("umbracoFile", test, fileStream);
  • AmandaEly 123 posts 379 karma points
    Apr 15, 2015 @ 16:19


    I am using Umbracocms.core version 7.2.2. I think the problem is that IMedia.SetValue in that version just doesn't have an overload that takes three arguments.

    I am trying to upload fles from my local C drive. I have tried both the MemoryStream and the FileStream method. Firstly, the SetValue method only takes two arguments (not three, as in the previous examples). So, having created my image using

    var newImage = _mediaService.CreateMedia(name, gallery, "Image");

     I used:                        

    newImage.SetValue("umbracoFile", fileStream); 

    In either case, I got

    "The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments"

    What am I missing?


  • AmandaEly 123 posts 379 karma points
    Apr 15, 2015 @ 17:09

    Just upgraded to Umbracocms version 7.2.4 but it still crashes.

  • Hefin Jones 39 posts 161 karma points
    Jun 26, 2015 @ 11:00
    Hefin Jones

    I've also had the issue "No overload for method 'SetValue' takes 3 arguments" .... I resolved this by adding to the top of my controller / class file:

    using Umbraco.Core.Models;

    Hope this helps :-)

Please Sign in or register to post replies

Write your reply to: