diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Collections.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Collections.cs index ab1b378c92..58cbb43cbf 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Collections.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Collections.cs @@ -95,7 +95,12 @@ public static partial class UmbracoBuilderExtensions builder.ContentIndexHandlers().Add(() => builder.TypeLoader.GetTypes()); WebhookPayloadType webhookPayloadType = Constants.Webhooks.DefaultPayloadType; - if (builder.Config.GetSection(Constants.Configuration.ConfigWebhookPayloadType).Value is not null) + + // IntelliSense indicates that GetSection cannot return null. However, in certain unit test setups, + // the configuration may not be fully initialized, leading to GetSection returning null. This null + // check ensures that the code behaves correctly in such scenarios and prevents potential null + // reference exceptions during testing. + if (builder.Config.GetSection(Constants.Configuration.ConfigWebhookPayloadType)?.Value is not null) { webhookPayloadType = builder.Config.GetValue(Constants.Configuration.ConfigWebhookPayloadType); }