U4-8346 - Umbraco.Core.Services.ContentService.Save fails on Azure when used in a separate thread

Created by Giordano 18 Apr 2016, 15:09:34 Updated by Martin K 26 Feb 2017, 17:27:25

I have a Umbraco 7.3.7 website deployed on Azure (one instance), which performs some operations inside a thread.

Sometimes Umbraco.Core.Services.ContentService.Save fails without a clear reason.

This is the log of the error: System.AggregateException: One or more errors occurred. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Umbraco.Web.RequestLifespanMessagesFactory.Get() at Umbraco.Core.Services.ContentService.Save(IContent content, Boolean changeState, Int32 userId, Boolean raiseEvents) at Umbraco.Core.Services.ContentService.Umbraco.Core.Services.IContentServiceOperations.Save(IContent content, Int32 userId, Boolean raiseEvents) at Umbraco.Core.Services.ContentService.Save(IContent content, Int32 userId, Boolean raiseEvents) at MyApp.Helpers.AzureJobHelper.<>c__DisplayClass0_0.b__0(IJob j) at Microsoft.WindowsAzure.MediaServices.Client.IJobExtensions.<>c__DisplayClass3.b__2(Object originalJob) at System.Threading.Tasks.Task1.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of inner exception stack trace --- at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at MyApp.Helpers.AzureJobHelper.GetAssetFromEncodingJob(IJob job, IContent video) at MyApp.Tasks.PublishMovieToMediaServicesTask.Run(Guid id)

+Note:+ Before to perform any operations, I ensure the Umbraco context in this way (as suggested https://gist.github.com/sniffdk/7600822): public static void EnsureUmbracoContext() { if (UmbracoContext.Current == null) { LogHelper.Info(typeof (UmbracoHelperSingleton), "Executing UmbracoContext.EnsureContext"); try { var httpContextCurrent = new System.Web.HttpContextWrapper(new System.Web.HttpContext(new System.Web.Hosting.SimpleWorkerRequest("dummy.aspx", "", new StringWriter()))); UmbracoContext.EnsureContext( httpContext: httpContextCurrent, applicationContext: ApplicationContext.Current, webSecurity: new Umbraco.Web.Security.WebSecurity(httpContextCurrent, ApplicationContext.Current), umbracoSettings: Umbraco.Core.Configuration.UmbracoConfig.For.UmbracoSettings(), urlProviders: Umbraco.Web.Routing.UrlProviderResolver.Current.Providers, replaceContext: false ); } catch (Exception ex) { LogHelper.Error(typeof (UmbracoHelperSingleton), "Fault to EnsureContext", ex); } } }

Do you know the reason? Thanks

Comments

Martin K 26 Feb 2017, 17:27:25

Of course this thread is fucking dead... Bump


Priority: Major

Type: Bug

State: Submitted

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.3.7

Due in version:

Sprint:

Story Points:

Cycle: