Copied to clipboard

Flag this post as spam?

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


  • Andreas Iseli 150 posts 427 karma points
    Mar 12, 2013 @ 11:41
    Andreas Iseli
    0

    Console Application - Publishing Problem

    I followed Mortens example to create a console application adding items to the content service:

    https://github.com/sitereactor/umbraco-console-example

    I'm able to add items, but the publish never works. It always gives me the following error:

    Oops: this document is published but is not in the cache (internal error)

     

    Does any have the same problem or does for someone works the publishing of content items using the ContentService ?

  • Morten Christensen 596 posts 2769 karma points admin hq c-trib
    Mar 12, 2013 @ 11:51
    Morten Christensen
    100

    I'm pretty sure that publishing won't work though a Console Application as it's tied into a lot of legacy code that writes to the xml cache and puts the same cache in HttpContext.Items (as far as I remember - at least something to do with HttpContext).
    It should however write the xml to the cmsContentXml table, so that its ready for generating the xml cache, so having used Publish/SaveAndPublish from your Console you could remove the umbraco.config file, and start the website to have it regenerate the actual cache. It might not be the workaround you were hoping for, but thats the only thing that is currently possible because of the legacy code involved with publishing.

    - Morten 

  • Andreas Iseli 150 posts 427 karma points
    Mar 12, 2013 @ 12:23
    Andreas Iseli
    0

    Thanks for you answer. Removing the config file and doing an IIS reset after the import fixes the problem.

  • Andreas Iseli 150 posts 427 karma points
    Mar 13, 2013 @ 09:24
    Andreas Iseli
    0

    I've marked your answer now as solution. Just for your information: HttpContext.Items is for the current request only. Considering a caching mechanism I either think is using HttpRuntime.Cache oder HttpContext.Cache. I'll once dive deeper into the source code here ;-)

  • Morten Christensen 596 posts 2769 karma points admin hq c-trib
    Mar 13, 2013 @ 09:28
    Morten Christensen
    1

    Look for the umbraco.content Class. That should contain everything with regards to publishing to the XML cache. But I must warn you that it hurts the eyes ;)

  • bparks 23 posts 78 karma points
    Jun 08, 2013 @ 10:37
    bparks
    0

    Did this issue ever get resolved?  I'm running 6.0.6 and attempting to call SaveAndPublish() on ContentService (from an external application) and am still seeing the message "Oops: this document is published but is not in the cache (internal error)" .

    My app needs to create/save/publish documents and can't require user intervention to "republish all" or reset IIS. 

  • Andreas Iseli 150 posts 427 karma points
    Jun 08, 2013 @ 15:03
    Andreas Iseli
    0

    Hi bparks

    Sorry currently there is no simpler way than doing an iis reset. Perhaps a webapp recycle may help as well.

    I did not have a deeper look into the publishing of the XML cache because I required the code for a one-time import only. So I just did an iisreset afterwards.

    Regards

  • Morten Primdahl 1 post 21 karma points
    Aug 30, 2013 @ 13:17
    Morten Primdahl
    0

    I also have an external app that needs to create/save and publish documents. Now i followed the information found here without it solving the issue. I tried to do IIS Reset and the documents still does not find its way into the cache, but just sits nicely in the content tree with the "Oops: this document is published but is not in the cache (internal error)"

    I then tried to do a RefreshContent via the umbraco.library but this returns an exception with the following data:

    Exception Message:
    Value cannot be null.
    Parameter name: refresher

    Stacktrace:
       at Umbraco.Core.Sync.DefaultServerMessenger.MessageSeversForIdsOrJson(IEnumerable`1 servers, ICacheRefresher refresher, MessageType dispatchType, IEnumerable`1 ids, String jsonPayload)
       at Umbraco.Core.Sync.DefaultServerMessenger.PerformRefreshAll(IEnumerable`1 servers, ICacheRefresher refresher)
       at Umbraco.Web.Cache.DistributedCache.RefreshAll(Guid factoryGuid, Boolean allServers)
       at Umbraco.Web.Cache.DistributedCache.RefreshAll(Guid factoryGuid)
       at Umbraco.Web.Cache.DistributedCacheExtensions.RefreshAllPageCache(DistributedCache dc)
       at umbraco.library.RefreshContent()
       at Forum_import.Program.RepublishAll(IContentService contentService) in d:\Projects\umbraco\CP-Forum\Forum_import\Forum_import\Program.cs:line 148
       at Forum_import.Program.Main(String[] args) in d:\Projects\umbraco\CP-Forum\Forum_import\Forum_import\Program.cs:line 105
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       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()

    The RefreshContent method does not require any parameters, so i am wondering if it could be the nodes created via the console app that needs to set other properties than the one crafted in the documenttype for the nodes being created.

    Regards

    Morten

     

  • Morten Christensen 596 posts 2769 karma points admin hq c-trib
    Aug 30, 2013 @ 13:32
    Morten Christensen
    0

    Morten,

    You cannot publish from a console application. You can save it, but publishing will never work because you are not in a webcontext.

    Only work around would be to save and then maybe set a release that for scheduled publishing or call a webserivce that is running within a webcontext that publishes the necessary content. But one thing to be aware of is stale cache, so the best advice would be to avoid publishing from something like a Console application.

    - Morten

  • lj 81 posts 425 karma points
    Sep 18, 2013 @ 19:20
    lj
    0

    I am having a similar problem when creating media types using a console application. I can get the media type (image) uploaded and saved to the correct folder but unitl I go into the umbraco backend and save here the image wont apprear when referenced from a front end razor script. I tried republishing the whole site ( that works for similar problem when adding new content above) but does not work for media. Anyone any suggestions. I am adding hundreds of these images at a time (linked to products in ucommerce).

  • Taras 30 posts 151 karma points
    Oct 02, 2013 @ 23:54
    Taras
    0
  • Kevin Nolan 9 posts 60 karma points
    Jul 29, 2014 @ 05:05
    Kevin Nolan
    1

    Hey all,

    Just sharing my solution to this problem. I've written a console app that poll's an FTP server for NewsML files for publishing within my Umbraco site.

    To get around the publishing issue I created an API with the UmbracoApiController - when items are ready to be published my console app posts the node ids to the API which publishes them to the cache. My code is still a little crude as I've only just got it working. Example is below

    My console app sends a comma delimited string of node id's to the API once the nodes have been saved to the DB and are ready for publishing. 

    using (WebClient wc = new WebClient())
                                {
                                  string HtmlResult = wc.UploadString("http://localhost:51245/umbraco/api/ContentAPI/PublishItems?nodes=" + nodestring, "");
                                }

    My API then does the following

    public class ContentAPIController : UmbracoApiController
        {
            [HttpPost]
            public string PublishItems(string nodes) 
            {
                var contentService = Services.ContentService;
                foreach (var item in nodes.Split(',').ToArray())
                {
                    if (item != "")
                    {
                        var pubItem = contentService.GetById(Convert.ToInt32(item));
                        contentService.SaveAndPublish(pubItem);
                    }
                }
                return "published";
    
            }
    
    
        }

    It's a workaround and needs more refinement but at this stage it seems like it'll work well for my purposes.

    Cheers 

Please Sign in or register to post replies

Write your reply to:

Draft