dotnet/wpf · error · ArgumentException

Microsoft.Windows.Controls.SR.RibbonGroupsPanel_InvalidRegis…

Error message

Microsoft.Windows.Controls.SR.RibbonGroupsPanel_InvalidRegistrationParameter

What it means

RibbonGroupsPanel.RegisterStarLayoutProvider only accepts objects implementing IProvideStarLayoutInfo (the full interface), not the base IProvideStarLayoutInfoBase. If the cast fails, an ArgumentException with resource key RibbonGroupsPanel_InvalidRegistrationParameter is thrown. This guards the panel's star-layout bookkeeping, which relies on members only present on the derived interface.

Solutions

  1. Pass an object that implements IProvideStarLayoutInfo (IProvideStarLayout, IProvideStarLayoutInfoBase, ISupportStarLayout) to RegisterStarLayoutProvider.
  2. Before calling, check `provider is IProvideStarLayoutInfo` and skip or convert otherwise.
  3. If you own the provider type, make it implement IProvideStarLayoutInfo instead of only IProvideStarLayoutInfoBase.

Example fix

// before
panel.RegisterStarLayoutProvider(myBaseProvider);
// after
if (myBaseProvider is IProvideStarLayoutInfo fullProvider)
{
    panel.RegisterStarLayoutProvider(fullProvider);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (provider is not IProvideStarLayoutInfo) throw new ArgumentException(nameof(provider));
panel.RegisterStarLayoutProvider(provider);

Type guard

static bool IsValidStarLayoutProvider(IProvideStarLayoutInfoBase p) => p is IProvideStarLayoutInfo;

Try / catch

try { panel.RegisterStarLayoutProvider(provider); }
catch (ArgumentException ex) when (ex.ParamName == "starLayoutInfoProvider") { /* log / substitute valid provider */ }

Prevention

When it happens

Trigger: Calling RegisterStarLayoutProvider with any object that implements only IProvideStarLayoutInfoBase (e.g. a custom ISupportStarLayout provider or a mock) instead of IProvideStarLayoutInfo.

Common situations: Custom ribbon panel/star-layout implementations, unit-test fakes built against the base interface, or code written against documentation that suggested the base type was sufficient.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/866dc7ad531072ef. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/Primitives/RibbonGroupsPanel.cs:55

        /// <summary>
        ///   Initializes static members of the RibbonGroupsContainer class.
        /// </summary>
        static RibbonGroupsPanel()
        {
            OrientationProperty.OverrideMetadata(typeof(RibbonGroupsPanel), new FrameworkPropertyMetadata(Orientation.Horizontal, null, new CoerceValueCallback(CoerceOrientation)));
        }

        #endregion

        #region ISupportStarLayout Members

        public void RegisterStarLayoutProvider(IProvideStarLayoutInfoBase starLayoutInfoProvider)
        {
            ArgumentNullException.ThrowIfNull(starLayoutInfoProvider);
            IProvideStarLayoutInfo provider = starLayoutInfoProvider as IProvideStarLayoutInfo;
            if (provider == null)
            {
                throw new ArgumentException(Microsoft.Windows.Controls.SR.RibbonGroupsPanel_InvalidRegistrationParameter, nameof(starLayoutInfoProvider));
            }
            if (!_registeredStarLayoutProviders.Contains(provider))
            {
                _registeredStarLayoutProviders.Add(provider);
                InvalidateMeasure();
            }
        }

        public void UnregisterStarLayoutProvider(IProvideStarLayoutInfoBase starLayoutInfoProvider)
        {
            ArgumentNullException.ThrowIfNull(starLayoutInfoProvider);
            IProvideStarLayoutInfo provider = starLayoutInfoProvider as IProvideStarLayoutInfo;
            if (provider == null)
            {
                throw new ArgumentException(Microsoft.Windows.Controls.SR.RibbonGroupsPanel_InvalidRegistrationParameter, nameof(starLayoutInfoProvider));
            }
            if (_registeredStarLayoutProviders.Contains(provider))
            {

View on GitHub (pinned to 81131a70a4)