cefsharp/CefSharp · error · NotImplementedException

Replace not implemented yet

Error message

Replace not implemented yet

What it means

Thrown by the example NonReloadingTabControl.OnItemsChanged when the underlying ObservableCollection raises a Replace action. This custom TabControl keeps all tabs alive (non-reloading) by managing ContentPresenters manually; it handles Reset/Add/Remove but explicitly has not implemented Replace, so replacing an item in the bound collection throws NotImplementedException.

Source

Thrown at CefSharp.Wpf.Example/Controls/NonReloadingTabControl.cs:95

                    {
                        foreach (var item in e.OldItems)
                        {
                            var cp = FindChildContentPresenter(item);
                            if (cp != null)
                            {
                                itemsHolderPanel.Children.Remove(cp);
                            }
                        }
                    }

                    // Don't do anything with new items because we don't want to
                    // create visuals that aren't being shown

                    UpdateSelectedItem();
                    break;

                case NotifyCollectionChangedAction.Replace:
                    throw new NotImplementedException("Replace not implemented yet");
            }
        }

        protected override void OnSelectionChanged(SelectionChangedEventArgs e)
        {
            base.OnSelectionChanged(e);
            UpdateSelectedItem();
        }

        private void UpdateSelectedItem()
        {
            if (itemsHolderPanel == null)
            {
                return;
            }

            // Generate a ContentPresenter if necessary
            var item = GetSelectedTabItem();

View on GitHub (pinned to 16bc6e0711)

Solutions

  1. Avoid Replace semantics on the bound collection: instead Remove then Add, or Clear then re-populate, which this control handles.
  2. If you must replace, remove the old item and insert the new one at the same index.
  3. Subclass NonReloadingTabControl and implement the Replace case by removing the old ContentPresenter and creating one for the new item.
  4. Switch to a standard TabControl if Replace support is essential and you do not need the non-reloading behavior.

Example fix

// before
tabs[0] = new BrowserTabViewModel(url); // throws NotImplementedException

// after
var old = tabs[0];
tabs.Remove(old);
tabs.Insert(0, new BrowserTabViewModel(url));
Defensive patterns

Strategy: fallback

Validate before calling

// Avoid Replace on collections bound to NonReloadingTabControl.
// Use Remove + Insert instead of index assignment:
tabs.Remove(oldItem);
tabs.Insert(index, newItem);

Try / catch

try { tabs[0] = newItem; }
catch (NotImplementedException) { tabs.Remove(tabs[0]); tabs.Insert(0, newItem); }

Prevention

When it happens

Trigger: Replacing an element in the ObservableCollection bound to NonReloadingTabControl.Items, e.g. `tabs[0] = newTab` or assigning by index; an observable collection whose source performs replace operations.

Common situations: Swapping a tab's view model in place; using ObservableCollection<T>[i] = value; a refresh pattern that replaces items rather than clearing and re-adding.

Related errors


AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13). Data as JSON: /api/errors/7897befa25787e78. Report an issue: GitHub.