PrismLibrary/Prism · error · ArgumentNullException

configureSegment

Error message

configureSegment

What it means

TabbedSegmentBuilder.CreateTab(Action<ICreateTabBuilder>) validates its configureSegment delegate with ArgumentNullException. Passing a null delegate throws immediately; the exception's parameter name is "configureSegment".

Solutions

  1. Always pass a non-null delegate; if no configuration is needed pass a no-op: `b => { }`.
  2. Guard your own helper methods before forwarding the delegate to CreateTab.
  3. Fix the caller that computes the delegate to ensure it isn't null.

Example fix

// before
tabbedBuilder.CreateTab(null); // ArgumentNullException
// after
tabbedBuilder.CreateTab(b => { });
// or guard:
if (configure is null) throw new ArgumentNullException(nameof(configure));
Defensive patterns

Strategy: validation

Validate before calling

if (configureSegment is null)
    throw new ArgumentNullException(nameof(configureSegment));
tabbedBuilder.CreateTab(configureSegment);

Type guard

bool HasConfigurator(Action<ICreateTabBuilder> a) => a is not null;

Try / catch

try { tabbedBuilder.CreateTab(configureSegment); }
catch (ArgumentNullException ex) when (ex.ParamName == "configureSegment")
{
    tabbedBuilder.CreateTab(b => { }); // no-op configuration
}

Prevention

When it happens

Trigger: Calling `tabbedBuilder.CreateTab(null)` or forwarding a null callback from your own helper method into CreateTab.

Common situations: Wrapping CreateTab in a helper with an optional Action parameter that defaults to null; dynamic code paths that skip building the delegate.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/c4785c49b7c32888. Report an issue: GitHub.

Appendix: source

Thrown at src/Maui/Prism.Maui/Navigation/Builder/TabbedSegmentBuilder.cs:63

    public string Segment => BuildSegment();

    public ITabbedSegmentBuilder AddSegmentParameter(string key, object value)
    {
        _parameters.Add(key, value);
        return this;
    }

    public ITabbedSegmentBuilder UseModalNavigation(bool useModalNavigation)
    {
        return AddSegmentParameter(KnownNavigationParameters.UseModalNavigation, useModalNavigation);
    }

    public ITabbedSegmentBuilder CreateTab(Action<ICreateTabBuilder> configureSegment)
    {
        if (configureSegment is null)
        {
            throw new ArgumentNullException(nameof(configureSegment));
        }

        var builder = new CreateTabBuilder(((IRegistryAware)_builder).Registry);
        configureSegment(builder);
        return AddSegmentParameter(KnownNavigationParameters.CreateTab, builder.Segment);
    }

    public ITabbedSegmentBuilder SelectedTab(string segmentName)
    {
        return AddSegmentParameter(KnownNavigationParameters.SelectedTab, segmentName);
    }

    public ITabbedSegmentBuilder Title(string title)
    {
        return AddSegmentParameter(KnownNavigationParameters.Title, title);
    }

    private string BuildSegment()

View on GitHub (pinned to 358118cd64)