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.
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 ;-)
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 ;)
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.
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.
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.
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.
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).
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.
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 ?
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
Thanks for you answer. Removing the config file and doing an IIS reset after the import fixes the problem.
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 ;-)
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 ;)
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.
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
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,
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
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).
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.
My API then does the following
It's a workaround and needs more refinement but at this stage it seems like it'll work well for my purposes.
Cheers
is working on a reply...