Copied to clipboard

Flag this post as spam?

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


  • Rasmus Fjord 675 posts 1566 karma points c-trib
    May 20, 2015 @ 08:24
    Rasmus Fjord
    0

    Creating media from console app, fails

    Hey there :)

    Im loading in data using a console application based upon the example from Morten, https://github.com/sitereactor/umbraco-console-example. Ive upgraded the solution with nuget so it should be 7.2.5.

    The content creation runs smooth no biggy there.

    When im creating media it fails at the .setvalue function.

    My code looks like this, quite simple :

     byte[] response = new System.Net.WebClient().DownloadData(raw.ImageUrl);
                        System.IO.MemoryStream strm = new MemoryStream(response);
    
                        var imgnode = mediaService.CreateMedia("image", 2406, "Image");
                        imgnode.SetValue("umbracoFile", strm);
    
                        mediaService.Save(imgnode);
    
                        //set to content
                        item.SetValue("productImages", imgnode.Id.ToString());
                        contentService.SaveAndPublish(item);

     

    When the stream gets added it fails with :

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException was unhandled
      HResult=-2146233088
      Message=The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments
      Source=Anonymously Hosted DynamicMethods Assembly
      StackTrace:
           at CallSite.Target(Closure , CallSite , Object , String , Object )
           at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)
           at Umbraco.Core.Models.ContentBase.SetValue(String propertyTypeAlias, Object value)
           at UmbConsole.Program.FetchAndAddPictures(Int32 productcatid, List`1 productsraw, IContentService contentService, IMediaService mediaService) in c:\Repositories\xy-umbraco\UmbConsole\Program.cs:line 113
           at UmbConsole.Program.Main(String[] args) in c:\Repositories\xy-umbraco\UmbConsole\Program.cs:line 93
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: 
    

    Ive done through a webcotroller before for file upload but this fails dunno if the console part has anything to do with it ? Tried alot of different things but nothing sticks.

Please Sign in or register to post replies

Write your reply to:

Draft