cefsharp/CefSharp · error · Exception

Please provide a valid command parameter for binding

Error message

Please provide a valid command parameter for binding

What it means

Thrown by the WPF example MainWindow.OpenTabCommandBinding when the routed command parameter (e.Parameter) is null or empty after ToString(). The handler opens a new browser tab at the given URL, so a missing/blank parameter has no target to navigate to and is rejected. It is example-code-level validation, not framework logic.

Source

Thrown at CefSharp.Wpf.Example/MainWindow.xaml.cs:241

                    {
                        MessageBox.Show("Pdf was saved to " + dialog.FileName);
                    }
                    else
                    {
                        MessageBox.Show("Unable to save Pdf, check you have write permissions to " + dialog.FileName);
                    }

                }
            }
        }

        private void OpenTabCommandBinding(object sender, ExecutedRoutedEventArgs e)
        {
            var url = e.Parameter.ToString();

            if (string.IsNullOrEmpty(url))
            {
                throw new Exception("Please provide a valid command parameter for binding");
            }

            CreateNewTab(url, true);

            TabControl.SelectedIndex = TabControl.Items.Count - 1;
        }

        private void Exit(object sender, ExecutedRoutedEventArgs e)
        {
            Close();
        }

        private void CloseTab(BrowserTabViewModel browserViewModel)
        {
            if (BrowserTabs.Remove(browserViewModel))
            {
                browserViewModel.WebBrowser?.Dispose();
            }

View on GitHub (pinned to 16bc6e0711)

Solutions

  1. Supply a non-empty CommandParameter in XAML: `CommandParameter="https://example.com"`.
  2. Bind CommandParameter to a non-null view-model property (the URL).
  3. In the handler, replace the throw with a guard that returns/ignores a null parameter instead of crashing.
  4. Validate/debug that the bound property is populated before the command can execute.

Example fix

// before (XAML)
<Button Content="Open" Command="{Binding OpenTabCommand}" /> <!-- no parameter -->

// after
<Button Content="Open" Command="{Binding OpenTabCommand}" CommandParameter="https://github.com" />
Defensive patterns

Strategy: validation

Validate before calling

var url = e.Parameter?.ToString();
if (!string.IsNullOrEmpty(url))
{
    CreateNewTab(url, true);
}

Prevention

When it happens

Trigger: Binding a Button/MenuItem Command to OpenTabCommand without supplying a CommandParameter, or with an empty/null parameter; e.Parameter being null so ToString() yields empty.

Common situations: XAML command binding missing the CommandParameter attribute; parameter bound to a property that is null at click time; copy-paste of a command binding without updating the URL argument.

Related errors


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