dotnet/maui · error · ArgumentException
path cannot be an empty string
Error message
path cannot be an empty string
What it means
ArgumentException from the Binding constructor when path is non-null but empty or whitespace. The constructor first rejects null path with ArgumentNullException, then this check rejects blank paths because a binding needs a real property path. Path is the primary identifier of the source member to bind.
Source
Thrown at src/Controls/src/Core/Binding.cs:46
public Binding()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Binding"/> class with the specified path, mode, converter, and source.
/// </summary>
/// <param name="path">The property path to bind to.</param>
/// <param name="mode">The binding mode.</param>
/// <param name="converter">The value converter to use.</param>
/// <param name="converterParameter">The parameter to pass to the converter.</param>
/// <param name="stringFormat">The string format to apply to the bound value.</param>
/// <param name="source">The source object for the binding.</param>
public Binding(string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null, object converterParameter = null, string stringFormat = null, object source = null)
{
if (path == null)
throw new ArgumentNullException(nameof(path));
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("path cannot be an empty string", nameof(path));
Path = path;
Converter = converter;
ConverterParameter = converterParameter;
Mode = mode;
StringFormat = stringFormat;
Source = source;
}
/// <summary>
/// Gets or sets the converter used to convert values between the source and target.
/// </summary>
public IValueConverter Converter
{
get { return _converter; }
set
{
ThrowIfApplied();View on GitHub (pinned to f377ff1c5e)
Solutions
- Supply a non-empty property path, e.g. nameof(MyViewModel.Title).
- If the path is computed, validate !string.IsNullOrWhiteSpace(path) before constructing the Binding.
- Use the Self binding source (BindingMode) or a relative source if you intentionally need no path.
Example fix
// before
var b = new Binding(_pathField);
// after
if (string.IsNullOrWhiteSpace(_pathField))
throw new InvalidOperationException("Binding path must be set.");
var b = new Binding(_pathField); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("Binding path is required.", nameof(path));
var binding = new Binding(path); Type guard
static bool IsValidBindingPath(string path) =>
!string.IsNullOrWhiteSpace(path); Prevention
- Always derive paths from nameof() or constants, never from unchecked input.
- Validate dynamic paths before constructing the Binding.
When it happens
Trigger: new Binding("") or new Binding(" "); building a Binding with a path variable that came back empty (e.g. nameof() on a private field in a context where it returned ""); constructing bindings from data that yielded an empty string.
Common situations: Dynamic binding construction from user/mapped data; refactor where the bound member was removed and nameof returned an unexpected token; copy-paste leaving the path blank.
Related errors
- propertyName
- returnType
- declaringType
- Cannot apply relative binding when the target object is null
- indexPath
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/dbb492470056113d.
Report an issue: GitHub.