Null reference exception when calling UpdateDocumentCache() via API
I'm using the Umbraco API to dynamically create/modify documents.
I can publish the document just fine with Document.Publish(), but when I call umbraco.library.UpdateDocumentCache(doc.Id) afterwards I get the below null reference error. This happens for both documents I've newly created and documents that were just modified.
The code I'm using is basically what is shown on the API cheatsheet example:
Object reference not set
to an instance of an object. at
umbraco.presentation.UmbracoContext.get_Current()
at umbraco.presentation.nodeFactory.Node..ctor(Int32 NodeId)
at
umbraco.presentation.nodeFactory.UmbracoSiteMapProvider.loadNodes(String
parentId, SiteMapNode parentNode)
at
umbraco.presentation.nodeFactory.UmbracoSiteMapProvider.BuildSiteMap()
at
umbraco.presentation.nodeFactory.UmbracoSiteMapProvider.UpdateNode(Node
node)
at umbraco.content.PublishNodeDo(Document d, XmlDocument
xmlContentCopy, Boolean updateSitemapProvider)
at umbraco.content.UpdateDocumentCache(Document d)
at umbraco.content.UpdateDocumentCache(Int32 pageId)
at umbraco.library.UpdateDocumentCache(Int32 DocumentId)
at...
There's one issue I can't figure out though--I want to run the process in a separate thread because it can take quite a while to run and I don't want the client to receive a timeout error waiting for a response from the service. Once the data is received, it is saved and any issues at that point will be handled on the umbraco side, so all the calling client needs to know is that the data was received correctly and was in the correct format. Apparantly the HTTP context isn't available in a separate thread, so this causes the same null reference exception when calling UpdateDocumentCache() if I try to run this in a separate thread.
Does anyone have any suggestions regarding a way to better achieve this?
Danny ... Did you ever get this figured out? I'm running into the same problem. I have built an importer that reads an excel spreadsheet and creates/publishes content in the CMS based on the rows in the spreadsheet. I'm running the process in a separate thread as the import can take quite a while and I don't want to hang up the browser session. I'm getting the NullReferenceException on the actual Publish() call.
My content does get created so the error isn't hanging anything up but it's annoying to know it's happening. I'm running Umbraco 4.7.0 on IIS 7 and .Net 4 Framework.
Null reference exception when calling UpdateDocumentCache() via API
I'm using the Umbraco API to dynamically create/modify documents.
I can publish the document just fine with Document.Publish(), but when I call umbraco.library.UpdateDocumentCache(doc.Id) afterwards I get the below null reference error. This happens for both documents I've newly created and documents that were just modified.
The code I'm using is basically what is shown on the API cheatsheet example:
Object reference not set to an instance of an object. at umbraco.presentation.UmbracoContext.get_Current() at umbraco.presentation.nodeFactory.Node..ctor(Int32 NodeId) at umbraco.presentation.nodeFactory.UmbracoSiteMapProvider.loadNodes(String parentId, SiteMapNode parentNode) at umbraco.presentation.nodeFactory.UmbracoSiteMapProvider.BuildSiteMap() at umbraco.presentation.nodeFactory.UmbracoSiteMapProvider.UpdateNode(Node node) at umbraco.content.PublishNodeDo(Document d, XmlDocument xmlContentCopy, Boolean updateSitemapProvider) at umbraco.content.UpdateDocumentCache(Document d) at umbraco.content.UpdateDocumentCache(Int32 pageId) at umbraco.library.UpdateDocumentCache(Int32 DocumentId) at...
Forgot to add version information (tried to edit, but I get an xslt error)
Umbraco 1.4.2, asp.net 3.5, IIS6 on Server 2003
Note that this code is getting run from a WCF REST service I created that is running under the same website as Umbraco.
Figured it out!
The issue was due to the HTTPContext not being available since I was running a WCF service.
To make this work, all I had to do was enable asp.net compability in the web.config under the system.serviceModel section:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
And then add the following attribute on the service class itself:
There's one issue I can't figure out though--I want to run the process in a separate thread because it can take quite a while to run and I don't want the client to receive a timeout error waiting for a response from the service. Once the data is received, it is saved and any issues at that point will be handled on the umbraco side, so all the calling client needs to know is that the data was received correctly and was in the correct format. Apparantly the HTTP context isn't available in a separate thread, so this causes the same null reference exception when calling UpdateDocumentCache() if I try to run this in a separate thread.
Does anyone have any suggestions regarding a way to better achieve this?
Bump, does anyone know how to publish documents in a separate thread running in Umbraco?
Danny ... Did you ever get this figured out? I'm running into the same problem. I have built an importer that reads an excel spreadsheet and creates/publishes content in the CMS based on the rows in the spreadsheet. I'm running the process in a separate thread as the import can take quite a while and I don't want to hang up the browser session. I'm getting the NullReferenceException on the actual Publish() call.
My content does get created so the error isn't hanging anything up but it's annoying to know it's happening. I'm running Umbraco 4.7.0 on IIS 7 and .Net 4 Framework.
is working on a reply...