dotnet/wpf · error · NotSupportedException

NotSupportedException (ConvertBack not supported)

Error message

NotSupportedException (ConvertBack not supported)

What it means

ViewIsGridViewConverter checks whether a value is a GridView and its ConvertBack throws NotSupportedException to signal that a view can never be converted back to a GridView. Unlike its siblings this is a NotSupportedException, an intentional one-way converter contract.

Solutions

  1. Declare the binding as Mode=OneWay.
  2. Never bind a source property back through this converter; use separate converters per direction.
  3. If round-trip semantics are required, write a custom converter implementing ConvertBack meaningfully.

Example fix

// before
<ListView.View Binding="{Binding CurrentView, Converter={StaticResource ViewIsGridViewConverter}, Mode=TwoWay}" />
// after
<ListView.View Binding="{Binding CurrentView, Converter={StaticResource ViewIsGridViewConverter}, Mode=OneWay}" />
Defensive patterns

Strategy: validation

Validate before calling

if (binding.Mode != BindingMode.OneWay)
    throw new InvalidOperationException("ViewIsGridViewConverter supports only OneWay bindings.");

Type guard

static bool IsGridView(object? v) => v is GridView;

Try / catch

try { ApplyBinding(); }
catch (NotSupportedException) { log.LogError("ViewIsGridViewConverter does not support ConvertBack"); }

Prevention

When it happens

Trigger: Binding with ViewIsGridViewConverter in TwoWay or OneWayToSource mode, causing ConvertBack invocation.

Common situations: ListView.View bindings accidentally set to TwoWay; refactorings that flip binding modes in styles or templates.

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/4943fd91a546aa09. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Controls/ViewIsGridViewConverter.cs:23

using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Controls;
using System.Windows.Data;

namespace Fluent.Controls
{
    internal class ViewIsGridViewConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // Returns true if value is a GridView, otherwise false
            return value is GridView;
        }

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

View on GitHub (pinned to 81131a70a4)