{"record":{"id":"bc682663f6a548f4","repo":"unoplatform/uno","slug":"the-name-value-is-already-defined-in-this-scop","errorCode":null,"errorMessage":"The name '{value}' is already defined in this scope","messagePattern":"The name '(.+?)' is already defined in this scope","errorType":"validation","errorClass":"XamlGenerationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs","lineNumber":3741,"sourceCode":"\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}\n\t\t\t}\n\n\t\t\treturn null;\n\t\t}\n","sourceCodeStart":3723,"sourceCodeEnd":3759,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs#L3723-L3759","documentation":"Thrown by ValidateName when the name is a valid identifier but is already present in CurrentScope.DeclaredNames — i.e. two elements in the same namescope share an x:Name. Duplicate names would collide the generated backing fields and break FindName resolution at runtime.","triggerScenarios":"Two sibling elements with the same x:Name in the same page/control namescope; copying a block and forgetting to rename; a DataTemplate's element name clashing with the page's.","commonSituations":"Copy-paste of UI blocks; refactor merging two XAML regions; designer duplicating names automatically.","solutions":["Rename one of the colliding elements to a unique x:Name within the scope.","Search the file (and the template) for the name to find all occurrences.","If names legitimately repeat across separate DataTemplates, note each template has its own namescope — but top-level page names must still be unique."],"exampleFix":"<!-- before -->\n<StackPanel>\n  <TextBox x:Name=\"Input\"/>\n  <TextBox x:Name=\"Input\"/>\n</StackPanel>\n\n<!-- after -->\n<StackPanel>\n  <TextBox x:Name=\"PrimaryInput\"/>\n  <TextBox x:Name=\"SecondaryInput\"/>\n</StackPanel>","handlingStrategy":"validation","validationCode":"# Detect duplicate x:Name within the same file scope\nGet-ChildItem -Recurse -Filter *.xaml | ForEach-Object {\n  $names = Select-String -Path $_.FullName -Pattern 'x:Name=\"([^\"]+)\"' |\n    ForEach-Object { $_.Matches[0].Groups[1].Value }\n  $names | Group-Object | Where-Object { $_.Count -gt 1 } |\n    ForEach-Object { Write-Warning \"Duplicate x:Name $($_.Name) x$($_.Count)\" }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep top-level element names unique across the page scope.","After copy-pasting a XAML block, immediately rename x:Name values."],"tags":["xaml","x-name","duplicate-name","validation","build"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}