06 Sep 2012
04 Mar 2011
Link to this post
I've created a GC-Based module and for it have written an import routine that parses a CSV of about 5000 lines, and creates a new content item for each line. This routine works fine, but with a CSV of this length, we get a page timeout before the operation completes.
Rather than increase the page timeout (it would have be be increased significantly), I tried executing my routine in a new thread. However, I get a null reference exception when calling ContentManager.Content.SaveContent(IContent content ) to create new content items.
After some investigation, it looks like the exception occurs in the StagedContent.Publish method, and occurs when the HostingEnvironent is checked. Since it's a new thread, i'm guessing HostingEnvironment is null.
Eventually giving up on that approach, I've decided to build a WCF web service for adding content items, and call it batches from my long-running task. However, upon creating my web service, I've realized that i still get a null reference exception when calling SateContent from within the service. It appears that this occurs because Whie the HostingEnvironment is now not null, it's IsHosted property returns true, causing the applicationPath local variable to be set to HttpContext.Current.Request.ApplicationPath, causing another null reference exception.
I'd subclass the StagedContent class and skip that piece of logic, but it's sealed.
Are there any workarounds for this? We very much need to be able to import these large chunks of data, and doing it from within InitializeControls in the page lifecylcle is not acceptable.