unoplatform/uno · error · InvalidOperationException
Value must be non-null string.
Error message
Value must be non-null string.
What it means
InvalidOperationException thrown by NameReferenceConverter.ConvertFrom (System.Xaml, ported from Mono) when the input value is null or an empty string. The converter returns a name reference string, so it requires a non-empty string input; null/empty is a usage error rather than an argument-null case (context was already validated).
Source
Thrown at src/SourceGenerators/System.Xaml/System.Windows.Markup/NameReferenceConverter.cs:60
{
return false;
}
var p = context.GetService (typeof (IXamlNameProvider)) as IXamlNameProvider;
return p != null && destinationType == typeof (string);
}
public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (context == null)
{
throw new ArgumentNullException ("context");
}
var s = value as string;
if (String.IsNullOrEmpty (s))
{
throw new InvalidOperationException ("Value must be non-null string.");
}
return s;
}
public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (context == null)
{
return null;
}
var p = context.GetService (typeof (IXamlNameProvider)) as IXamlNameProvider;
return p?.GetName (value);
}
}
}
View on GitHub (pinned to 0418340488)
Solutions
- Validate the input is a non-empty string before invoking ConvertFrom.
- Coerce null/empty to a sensible default name upstream of the converter.
- In XAML, ensure the name reference attribute has a value.
Example fix
// before
var name = (string)converter.ConvertFrom(ctx, culture, maybeEmpty);
// after
if (string.IsNullOrEmpty(maybeEmpty)) throw new ArgumentException("Name reference required.");
var name = (string)converter.ConvertFrom(ctx, culture, maybeEmpty); Defensive patterns
Strategy: validation
Validate before calling
static string SafeConvert(NameReferenceConverter c, ITypeDescriptorContext ctx, string value) { if (string.IsNullOrEmpty(value)) throw new ArgumentException("Name reference required.", nameof(value)); return (string)c.ConvertFrom(ctx, CultureInfo.InvariantCulture, value); } Type guard
static bool IsNonEmptyName(object value) => value is string s && s.Length > 0;
Try / catch
try { return (string)converter.ConvertFrom(ctx, culture, value); } catch (InvalidOperationException ex) when (ex.Message.Contains("non-null string")) { return string.Empty; } Prevention
- Validate input is a non-empty string before converting.
- Coerce null/empty upstream of the converter.
- Ensure XAML name-reference attributes always carry a value.
When it happens
Trigger: Passing null, string.Empty, or whitespace-only value to ConvertFrom once a valid context is present.
Common situations: A bound/config value that resolves to null or empty being fed to the converter, XAML where the reference is omitted, or default(string) passed programmatically.
Related errors
- context
- Type property must be set before calling ProvideValue method
- Item in the array must be an instance of '{0}'
- Name property is not set
- serviceProvider does not implement IXamlNameResolver
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/6a1bf7a4e9b71c1a.
Report an issue: GitHub.