Exception when running scheduled job

Vote:
 

I am having a problem with a scheduled job. The job is running fine when it's run manually, but when it's run on time automatic, I get an object reference not set exception. Any ideas?

privatestaticintTraverseXml(XmlDocument xmlDoc,PageReference importo,PageDataCollection children){PageTypeImportPageType=EPiServer.DataAbstraction.PageType.Load(SiteSettings.Settings.UnitPageTypeID);XmlDocument xmlDoc2 =newXmlDocument();

             xmlDoc2.Load(HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["ESsImportMappingsXML"]));Dictionary<string,string> propertyMappings =newDictionary<string,string>();foreach(XmlNode xmlnode in xmlDoc2.SelectNodes("/mappings/mapping")){
                propertyMappings.Add(xmlnode.Attributes["key"].Value.ToString(), xmlnode.Attributes["pagekey"].Value.ToString());}int count =0;XmlNodeList nodes = xmlDoc.SelectNodes("/pages/page");foreach(XmlNode node in nodes){Utility.CreatePage(node, importo, children, propertyMappings,ImportPageType);
                count++;}

 

#71165
May 13, 2013 10:33
Vote:
 

This exception is thrown because current context is inaccessible when a job is run by scheduler and HttpContext.Current is null.

You should find another way to load or resolve path to your resources.

#71182
Edited, May 13, 2013 12:31
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.