dotnet/wpf · error · NotSupportedException

new NotSupportedException()

Error message

new NotSupportedException()

What it means

The internal value converter for the 'Show Quick Access Toolbar below the Ribbon' checkable item implements only one-way conversion (bool/state to a RibbonCommand); its ConvertBack is intentionally unsupported. Calling it throws NotSupportedException because the binding for this menu item never needs two-way conversion.

Solutions

  1. Do not use this converter in TwoWay bindings; keep it one-way (Mode=OneWay) or omit the converter in your own bindings.
  2. Implement your own converter with a working ConvertBack if you need round-tripping of the Quick Access Toolbar position.
  3. If you control the code, wrap ConvertBack in try/catch NotSupportedException only when a one-way binding occasionally evaluates back.

Example fix

// before
Binding b = new Binding("IsChecked") { Converter = ribbonContextMenuConverter, Mode = BindingMode.TwoWay };

// after
Binding b = new Binding("IsChecked") { Converter = ribbonContextMenuConverter, Mode = BindingMode.OneWay };
Defensive patterns

Strategy: try-catch

Validate before calling

if (binding.Mode == BindingMode.TwoWay) throw new InvalidOperationException("ShowQuickAccessToolBar converter is one-way only");

Type guard

bool SupportsConvertBack(IValueConverter c) => c.GetType().Name != "ShowQuickAccessToolBarConverter"; // internal converter is one-way only

Try / catch

try { result = converter.ConvertBack(value, targetType, parameter, culture); }
catch (NotSupportedException) { result = value; /* converter is one-way by design */ }

Prevention

When it happens

Trigger: Invoking ConvertBack on the ShowQuickAccessToolBar converter, e.g. by creating a TwoWay or TwoWay-by-default binding whose converter is this internal converter, or calling it directly via reflection/custom binding code.

Common situations: Copy-pasting the Ribbon's internal converters into custom code, or building a custom binding with Mode=TwoWay that reuses the converter from RibbonContextMenu's QuickAccessToolBar menu items.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonContextMenu.cs:445

                        {
                            return RibbonCommands.ShowQuickAccessToolBarAboveRibbonCommand;
                        }
                    }
                }

                if (_mode == ConverterMode.Header)
                {
                    return ShowQATBelowText;
                }
                else
                {
                    return RibbonCommands.ShowQuickAccessToolBarBelowRibbonCommand;
                }
            }

            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new NotSupportedException();
            }
        }

        private static RibbonMenuItem GenerateMinimizeTheRibbonItem(RibbonContextMenu contextMenu)
        {
            RibbonMenuItem minimizeTheRibbonItem = new RibbonMenuItem
            {
                CanAddToQuickAccessToolBarDirectly = false,
                Header = MinimizeTheRibbonText
            };

            PropertyPath path = new PropertyPath("(0).(1).(2)");
            path.PathParameters.Add(ContextMenuService.PlacementTargetProperty);
            path.PathParameters.Add(RibbonControlService.RibbonProperty);
            path.PathParameters.Add(Ribbon.IsMinimizedProperty);

            Binding isCheckedBinding = new Binding () { Source = contextMenu, Path = path };
            minimizeTheRibbonItem.SetBinding(RibbonMenuItem.IsCheckedProperty, isCheckedBinding);

View on GitHub (pinned to 81131a70a4)