{"record":{"id":"6796c045e00c8330","repo":"unoplatform/uno","slug":"the-value-value-is-an-invalid-value-for-name","errorCode":null,"errorMessage":"The value '{value}' is an invalid value for 'Name' property","messagePattern":"The value '(.+?)' is an invalid value for 'Name' property","errorType":"validation","errorClass":"XamlGenerationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs","lineNumber":3736,"sourceCode":"\t\t\tvoid BuildCustomMarkupExtensionPropertyValue(IIndentedStringBuilder writer, XamlMemberDefinition member, string closure, string? resourceOwner)\n\t\t\t{\n\t\t\t\tvar propertyValue = GetCustomMarkupExtensionValue(member, closure, resourceOwner);\n\t\t\t\tif (!propertyValue.IsNullOrEmpty())\n\t\t\t\t{\n\t\t\t\t\twriter.AppendIndented($\"{closure}.{member.Member.Name} = {propertyValue};\\r\\n\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate static bool IsNotFrameworkElementButNeedsSourceLocation(XamlObjectDefinition objectDefinition)\n\t\t\t=> objectDefinition.Type.Name is \"VisualState\" or \"AdaptiveTrigger\" or \"StateTrigger\";\n\n\t\tprivate void ValidateName(string? value, IXamlLocation location)\n\t\t{\n\t\t\t// Nullable suppressions are due to https://github.com/dotnet/roslyn/issues/55507\n\t\t\tif (!SyntaxFacts.IsValidIdentifier(value!))\n\t\t\t{\n\t\t\t\tthrow new XamlGenerationException($\"The value '{value}' is an invalid value for 'Name' property\", location);\n\t\t\t}\n\n\t\t\tif (!CurrentScope.DeclaredNames.Add(value!))\n\t\t\t{\n\t\t\t\tthrow new XamlGenerationException($\"The name '{value}' is already defined in this scope\", location);\n\t\t\t}\n\t\t}\n\n\t\tprivate IPropertySymbol? FindLazyContentProperty(XamlMemberDefinition? implicitContentChild, INamedTypeSymbol? elementType)\n\t\t{\n\t\t\tif (implicitContentChild != null && elementType != null)\n\t\t\t{\n\t\t\t\tvar contentProperty = FindContentProperty(elementType);\n\n\t\t\t\tif (contentProperty != null && IsLazyVisualStateManagerProperty(contentProperty) && !HasDescendantsWithXName(implicitContentChild))\n\t\t\t\t{\n\t\t\t\t\treturn contentProperty;\n\t\t\t\t}","sourceCodeStart":3718,"sourceCodeEnd":3754,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs#L3718-L3754","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"<!-- before -->\n<TextBox x:Name=\"1st-name\"/>\n\n<!-- after -->\n<TextBox x:Name=\"FirstName\"/>","handlingStrategy":"validation","validationCode":"# Validate x:Name values are legal C# identifiers\nAdd-Type -AssemblyName 'Microsoft.CodeAnalysis.CSharp' -ErrorAction SilentlyContinue\n# Fallback regex equivalent of a valid C# identifier:\nGet-ChildItem -Recurse -Filter *.xaml | ForEach-Object {\n  Select-String -Path $_.FullName -Pattern 'x:Name=\"([^\"]+)\"' |\n    ForEach-Object {\n      $n = $_.Matches[0].Groups[1].Value\n      if ($n -notmatch '^[A-Za-z_][A-Za-z0-9_]*$') { Write-Warning \"$($_.Filename):$($_.LineNumber): invalid x:Name '$n'\" }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name x:Name values as valid C# identifiers (letter/underscore start, alphanumerics+underscore only).","Avoid designer-generated names with hyphens or leading digits."],"tags":["xaml","x-name","identifier","validation","build"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}