Copied to clipboard

Flag this post as spam?

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


  • Danny 49 posts 104 karma points
    Dec 20, 2010 @ 16:08
    Danny
    0

    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:

    doc.Publish(_systemUser);
    umbraco.library.UpdateDocumentCache(doc.Id);

    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...

  • Danny 49 posts 104 karma points
    Dec 20, 2010 @ 16:21
    Danny
    0

    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. 

  • Danny 49 posts 104 karma points
    Dec 20, 2010 @ 18:54
    Danny
    0

    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:

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

     

    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 49 posts 104 karma points
    May 19, 2011 @ 01:30
    Danny
    0

    Bump, does anyone know how to publish documents in a separate thread running in Umbraco?

  • Chester Campbell 98 posts 209 karma points
    Nov 11, 2011 @ 00:14
    Chester Campbell
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft