unoplatform/uno · error · XamlGenerationException
The value '{value}' is an invalid value for 'Name' property
Error message
The value '{value}' is an invalid value for 'Name' property What it means
Thrown by ValidateName when the x:Name value is not a valid C# identifier per Roslyn's SyntaxFacts.IsValidIdentifier. The x:Name becomes a generated backing field name, so it must be a legal identifier (letters, digits, underscores; not starting with a digit; no spaces or special chars).
Source
Thrown at src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:3736
void BuildCustomMarkupExtensionPropertyValue(IIndentedStringBuilder writer, XamlMemberDefinition member, string closure, string? resourceOwner)
{
var propertyValue = GetCustomMarkupExtensionValue(member, closure, resourceOwner);
if (!propertyValue.IsNullOrEmpty())
{
writer.AppendIndented($"{closure}.{member.Member.Name} = {propertyValue};\r\n");
}
}
}
private static bool IsNotFrameworkElementButNeedsSourceLocation(XamlObjectDefinition objectDefinition)
=> objectDefinition.Type.Name is "VisualState" or "AdaptiveTrigger" or "StateTrigger";
private void ValidateName(string? value, IXamlLocation location)
{
// Nullable suppressions are due to https://github.com/dotnet/roslyn/issues/55507
if (!SyntaxFacts.IsValidIdentifier(value!))
{
throw new XamlGenerationException($"The value '{value}' is an invalid value for 'Name' property", location);
}
if (!CurrentScope.DeclaredNames.Add(value!))
{
throw new XamlGenerationException($"The name '{value}' is already defined in this scope", location);
}
}
private IPropertySymbol? FindLazyContentProperty(XamlMemberDefinition? implicitContentChild, INamedTypeSymbol? elementType)
{
if (implicitContentChild != null && elementType != null)
{
var contentProperty = FindContentProperty(elementType);
if (contentProperty != null && IsLazyVisualStateManagerProperty(contentProperty) && !HasDescendantsWithXName(implicitContentChild))
{
return contentProperty;
}View on GitHub (pinned to 0418340488)
Solutions
- Rename to a valid C# identifier: start with a letter or underscore, use only alphanumerics and underscores.
- Avoid C# reserved keywords as names.
- Use PascalCase or camelCase consistent with the codebase.
Example fix
<!-- before --> <TextBox x:Name="1st-name"/> <!-- after --> <TextBox x:Name="FirstName"/>
Defensive patterns
Strategy: validation
Validate before calling
# Validate x:Name values are legal C# identifiers
Add-Type -AssemblyName 'Microsoft.CodeAnalysis.CSharp' -ErrorAction SilentlyContinue
# Fallback regex equivalent of a valid C# identifier:
Get-ChildItem -Recurse -Filter *.xaml | ForEach-Object {
Select-String -Path $_.FullName -Pattern 'x:Name="([^"]+)"' |
ForEach-Object {
$n = $_.Matches[0].Groups[1].Value
if ($n -notmatch '^[A-Za-z_][A-Za-z0-9_]*$') { Write-Warning "$($_.Filename):$($_.LineNumber): invalid x:Name '$n'" }
}
} Prevention
- Name x:Name values as valid C# identifiers (letter/underscore start, alphanumerics+underscore only).
- Avoid designer-generated names with hyphens or leading digits.
When it happens
Trigger: x:Name starting with a digit (x:Name="1stItem"); containing spaces, dots, or hyphens; using a C# keyword as a name in some cases; empty or whitespace-only names.
Common situations: Auto-generated names from a designer that include invalid characters; naming by a non-programmer convention; copy-paste from HTML id attributes that contain hyphens.
Related errors
- The name '{value}' is already defined in this scope
- Unable to find type '{objectDefinition.Type}'
- The {0} string passed in the colorString argument is not a r
- The {0} string passed in the colorString argument is not a r
- The {0} string passed in the colorString argument is not a r
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/6796c045e00c8330.
Report an issue: GitHub.