From 3520f2d1e4138e5da5350fafb5897d3fac2f0641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Knippers?= Date: Thu, 25 Jan 2018 08:56:46 +0100 Subject: [PATCH] Fix NullReferenceException when HttpContext is null This method will throw a NullReferenceException in contexts without an HttpContext, like is the case in background threads. As HttpContext is only used to set an isDebug flag, it seems more sensible to not throw in cases without an HttpContext, but simply set isDebug to false instead. If this is not acceptable behavior, could we perhaps look at something other than HttpContext.Current.IsDebuggingEnabled to decide whether isDebug should be set? --- .../PropertyEditors/ValueConverters/GridValueConverter.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs index 85599767d6..e169fa4506 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs @@ -40,12 +40,13 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters //TODO: Change all singleton access to use ctor injection in v8!!! //TODO: That would mean that property value converters would need to be request lifespan, hrm.... + bool isDebug = HttpContext.Current != null && HttpContext.Current.IsDebuggingEnabled; var gridConfig = UmbracoConfig.For.GridConfig( ApplicationContext.Current.ProfilingLogger.Logger, ApplicationContext.Current.ApplicationCache.RuntimeCache, new DirectoryInfo(IOHelper.MapPath(SystemDirectories.AppPlugins)), new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config)), - HttpContext.Current.IsDebuggingEnabled); + isDebug); var sections = GetArray(obj, "sections"); foreach (var section in sections.Cast()) @@ -112,4 +113,4 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters } } -} \ No newline at end of file +}