unoplatform/uno · error · XamlGenerationException

The TargetName property cannot be empty

Error message

The TargetName property cannot be empty

What it means

Thrown in the Storyboard attached-property branch when member.Member.Name == "TargetName", IsAttachedProperty is true, DeclaringType is Storyboard, but member.Value is null. Storyboard.SetTargetName requires a non-empty target name string; an empty value cannot be emitted into the generated SetTargetName call.

Source

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

							}
							else if (member.Member.Name == "DefaultBindMode"
								&& member.Member.PreferredXamlNamespace == XamlConstants.XamlXmlNamespace)
							{
								writer.AppendLineInvariantIndented("// DefaultBindMode {0}", member.Value);
							}
							else if (member.Member.Name == "Class" && member.Member.PreferredXamlNamespace == XamlConstants.XamlXmlNamespace)
							{
								writer.AppendLineInvariantIndented("// Class {0}", member.Value, member.Value);
							}
							else if (
								member.Member.Name == "TargetName" &&
								IsAttachedProperty(member) &&
								member.Member.DeclaringType?.Name == "Storyboard"
							)
							{
								if (member.Value == null)
								{
									throw new XamlGenerationException("The TargetName property cannot be empty", member);
								}

								var memberGlobalizedType = FindType(member.Member.DeclaringType)?.GetFullyQualifiedTypeIncludingGlobal() ?? GetGlobalizedTypeName(member.Member.DeclaringType.Name);
								writer.AppendLineInvariantIndented(@"{0}.SetTargetName({2}, ""{1}"");",
									memberGlobalizedType,
									this.RewriteAttachedPropertyPath(member.Value.ToString() ?? ""),
									writer.AppliedParameterName);

								writer.AppendLineInvariantIndented("{0}.SetTarget({2}, _{1}Subject);",
									memberGlobalizedType,
									member.Value,
									writer.AppliedParameterName);
							}
							else if (
								member.Member.Name == "TargetName" &&
								!IsAttachedProperty(member) &&
								(member.Member.DeclaringType?.Name.EndsWith("ThemeAnimation", StringComparison.Ordinal) ?? false)
							)

View on GitHub (pinned to 0418340488)

Solutions

  1. Provide a non-empty TargetName matching an x:Name of a target element in scope, e.g. Storyboard.TargetName="MyRectangle".
  2. Ensure the named target element exists with a matching x:Name in the same namescope.
  3. If the animation is template-scoped, confirm the target name exists within the template's namescope.

Example fix

<!-- before -->
<DoubleAnimation Storyboard.TargetName="" Storyboard.TargetProperty="Opacity"/>

<!-- after -->
<DoubleAnimation Storyboard.TargetName="MyRectangle" Storyboard.TargetProperty="Opacity"/>
Defensive patterns

Strategy: validation

Validate before calling

# Flag animations with empty Storyboard.TargetName
Get-ChildItem -Recurse -Filter *.xaml | ForEach-Object {
  Select-String -Path $_.FullName -Pattern 'Storyboard\.TargetName="\s*"' |
    ForEach-Object { Write-Warning "$($_.Filename):$($_.LineNumber): empty Storyboard.TargetName" }
}

Prevention

When it happens

Trigger: Writing <Storyboard ... Storyboard.TargetName=""> on an animation; a binding/markup that evaluates TargetName to nothing; an animation element with an empty TargetName attribute.

Common situations: Authoring an animation and leaving TargetName blank intending to set it later; copy-paste that drops the value; a malformed binding expression in the attribute.

Related errors


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