unoplatform/uno · error · XamlGenerationException

'{memberName}' is not defined on '{xamlObjectDefinition.Type

Error message

'{memberName}' is not defined on '{xamlObjectDefinition.Type.Name}'

What it means

Thrown by GetMember() when a required XAML member (attribute or child element) is not present on an object. GetMember is the non-null-throwing counterpart to FindMember; it is only called when the generator considers the member mandatory. It fires in three concrete call sites: a ResourceDictionary entry missing x:Key (XamlFileGenerator.cs:2527), a Style missing TargetType (line 6491), and a Setter that has Value but neither Property nor Target inside a styled target (line 6074). The error is an XamlGenerationException carrying the source location of the offending XAML node.

Source

Thrown at src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:2333

		{
			foreach (var member in xamlObjectDefinition.Members)
			{
				if (member.Member.Name == memberName && member.Member.PreferredXamlNamespace == ns)
				{
					return member;
				}
			}

			return null;
		}

		private XamlMemberDefinition GetMember(XamlObjectDefinition xamlObjectDefinition, string memberName)
		{
			var member = FindMember(xamlObjectDefinition, memberName);

			if (member == null)
			{
				throw new XamlGenerationException($"'{memberName}' is not defined on '{xamlObjectDefinition.Type.Name}'", xamlObjectDefinition);
			}

			return member;
		}

		private XClassName GetClassName(XamlObjectDefinition control)
		{
			var classMember = FindClassName(control);

			if (classMember == null)
			{
				throw new XamlGenerationException("Unable to find class name for toplevel control", control);
			}

			return classMember;
		}

		private XClassName? FindClassName(XamlObjectDefinition control)

View on GitHub (pinned to 0418340488)

Solutions

  1. Add the missing attribute the message names: for a dictionary entry add x:Key="myKey"; for a Style add TargetType="Button"; for a Setter add Property="Width".
  2. If the error points at a Setter/Target (line 6074 path), give the Setter either a Property="..." or Target="..." so the generator can resolve the property type.
  3. Open the file/line the exception reports (it carries IXamlLocation) and confirm the named member is actually spelled correctly (case-sensitive, no xmlns prefix mismatch).
  4. Run dotnet xstyler on the SamplesApp XAML to normalize structure, then rebuild.

Example fix

<!-- before -->
<Style>
  <Setter Value="20"/>
</Style>

<!-- after -->
<Style TargetType="Button">
  <Setter Property="Width" Value="20"/>
</Style>
Defensive patterns

Strategy: validation

Validate before calling

// Pre-build XAML lint (PowerShell or an MSBuild target) before invoking the generator:
# Ensure every Style has TargetType and every ResourceDictionary entry has x:Key
Select-String -Path 'src\**\*.xaml' -Pattern '<Style(?![^>]*TargetType)' |
  ForEach-Object { Write-Warning "$($_.Filename):$($_.LineNumber): <Style> missing TargetType" }
# Check dictionary entries without x:Key (heuristic):
Select-String -Path 'src\**\*.xaml' -Pattern '<(SolidColorBrush|Style|DataTemplate)(?![^>]*x:Key)' |
  ForEach-Object { Write-Warning "$($_.Filename):$($_.LineNumber): possible missing x:Key" }

Prevention

When it happens

Trigger: Authoring a <Style> element without a TargetType attribute; placing an entry inside a <ResourceDictionary> (or any IDictionary-backed collection) without an x:Key; writing a <Setter Value="..."> with no matching Property or Target inside a Style whose TargetType is set (the GetMember(member.Owner, "Target") call at line 6074 throws rather than falling through).

Common situations: Porting XAML from WPF/SL where keys were sometimes inferred; copy-paste of a Setter that drops the Property attribute; using a merged dictionary style that relies on implicit keys (Uno requires explicit keys); refactoring a Style and forgetting TargetType.

Related errors


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