unoplatform/uno · error · InvalidOperationException

Name property is not set

Error message

Name property is not set

What it means

InvalidOperationException thrown by Reference.ProvideValue (System.Xaml, ported from Mono) when the Name property is null. x:Reference resolves an element by name via IXamlNameResolver; without a name there is nothing to resolve. Name is normally supplied via the Reference(string name) constructor or the constructor argument in markup.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Windows.Markup/Reference.cs:57

		public Reference (string name)
		{
			Name = name;
		}

		[ConstructorArgument ("name")]
		public string Name { get; set; }

		public override object ProvideValue (IServiceProvider serviceProvider)
		{
			if (serviceProvider == null)
			{
				throw new ArgumentNullException ("serviceProvider");
			}

			if (Name == null)
			{
				throw new InvalidOperationException ("Name property is not set");
			}

			var r = serviceProvider.GetService (typeof (IXamlNameResolver)) as IXamlNameResolver;
			if (r == null)
			{
				throw new InvalidOperationException ("serviceProvider does not implement IXamlNameResolver");
			}

			var ret = r.Resolve (Name);
			if (ret == null)
			{
				ret = r.GetFixupToken (new string [] {Name}, true);
			}

			return ret;
		}
	}
}

View on GitHub (pinned to 0418340488)

Solutions

  1. Supply Name via the Reference(string name) constructor or set the property before ProvideValue.
  2. In XAML, ensure x:Reference has a name, e.g. {x:Reference MyElement}.
  3. Guard at the call site: if (ref.Name is null) ref.Name = expectedName; before evaluation.

Example fix

// before
var r = new Reference();
r.ProvideValue(sp); // Name is null

// after
var r = new Reference("MyElement");
r.ProvideValue(sp);
Defensive patterns

Strategy: validation

Validate before calling

static Reference RequireName(Reference r) => r.Name is null ? throw new InvalidOperationException("Reference.Name is required.") : r;

Type guard

static bool IsReady(Reference r) => !string.IsNullOrEmpty(r.Name);

Try / catch

try { return r.ProvideValue(sp); } catch (InvalidOperationException ex) when (ex.Message.Contains("Name property is not set")) { r.Name = fallbackName; return r.ProvideValue(sp); }

Prevention

When it happens

Trigger: Default-constructing Reference and calling ProvideValue without setting Name, or malformed x:Reference markup omitting the name.

Common situations: Programmatic construction that forgets the name, XAML where the x:Reference name attribute is missing/blank, or a binding producing null for the name.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/131ad1f1962b9e5b. Report an issue: GitHub.