NullReferenceException is thrown when having components with broken images


Description

SXA pages might fail to render with an unhandled exception if the responsive image variant of the image component points to a field with a broken link even if the page contains other components that are not affected. The following message can be found in Sitecore logs:

Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: Sitecore.XA.Feature.Stylelabs
   at Sitecore.XA.Feature.Stylelabs.Services.StylelabsDataExtractor.GetSrcAttributeValue(ImageField imageField)
   at Sitecore.XA.Feature.Stylelabs.Pipelines.RenderVariantField.RenderFallbackResponsiveMImage.RenderField(RenderVariantFieldArgs args)
   at Sitecore.XA.Foundation.Variants.Abstractions.Pipelines.RenderVariantField.RenderVariantFieldProcessor.Process(RenderVariantFieldArgs args)
   at (Object , Object )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)

Solution

To resolve the issue, consider the following options: