{"record":{"id":"7708d7d8f07bdc8a","repo":"dotnet/wpf","slug":"sr-simplefixupsmusthaveonename","errorCode":null,"errorMessage":"SR.SimpleFixupsMustHaveOneName","messagePattern":"SR\\.SimpleFixupsMustHaveOneName","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ServiceProviderContext.cs","lineNumber":297,"sourceCode":"            return ((IXamlNameResolver)this).GetFixupToken(names, false);\n        }\n\n        object IXamlNameResolver.GetFixupToken(IEnumerable<string> names, bool canAssignDirectly)\n        {\n            if (_xamlContext.NameResolutionComplete)\n            {\n                return null;\n            }\n\n            var token = new NameFixupToken\n            {\n                CanAssignDirectly = canAssignDirectly\n            };\n\n            token.NeededNames.AddRange(names);\n            if (token.CanAssignDirectly && token.NeededNames.Count != 1)\n            {\n                throw new ArgumentException(SR.SimpleFixupsMustHaveOneName, nameof(names));\n            }\n\n            // TypeConverter case (aka \"Initialization\")\n            if (_xamlContext.CurrentType is null)\n            {\n                // If this is OBJECT Initialization\n                if (_xamlContext.ParentProperty == XamlLanguage.Initialization)\n                {\n                    token.FixupType = FixupType.ObjectInitializationValue;\n\n                    // If this is object initialization syntax:\n                    //  SO Button>\n                    //    SM Background\n                    //       SO RefObject\n                    //         SM _Initialization\n                    //           V \"_name\"\n                    // This TC will return the RefObject and\n                    // The fixup is to Button.Background  (the grand parent)","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ServiceProviderContext.cs#L279-L315","documentation":"GetFixupToken builds a fixup token for deferred name resolution. When the token can assign directly (CanAssignDirectly), exactly one name must be supplied; otherwise the token throws ArgumentException(SimpleFixupsMustHaveOneName, nameof(names)).","triggerScenarios":"Calling IServiceProvider/IXamlNameResolver.GetFixupToken(names, canAssignDirectly: true) with a names collection whose Count != 1 (empty or multiple names).","commonSituations":"Custom IXamlNameResolver implementations or markup extensions forwarding all pending names with canAssignDirectly hardcoded true; forward-reference handling code that batches multiple unresolved names.","solutions":["Pass canAssignDirectly: false when more than one name is pending.","Only use the direct-assignment path when exactly one name remains unresolved.","Check names.Count() == 1 before requesting the token and fall back to the non-direct mode.","Catch ArgumentException and retry with canAssignDirectly set to false."],"exampleFix":"// before\nvar token = nameResolver.GetFixupToken(pendingNames, canAssignDirectly: true); // throws for 0 or 2+ names\n// after\nvar token = nameResolver.GetFixupToken(pendingNames, canAssignDirectly: pendingNames.Count() == 1);","handlingStrategy":"validation","validationCode":"int count = names?.Count() ?? 0;\nif (canAssignDirectly && count != 1) throw new ArgumentException($\"Direct assignment requires exactly one name, got {count}\");","typeGuard":"bool EligibleForDirectAssign(IEnumerable<string> names) => names != null && names.Count() == 1;","tryCatchPattern":"try { return resolver.GetFixupToken(names, canAssignDirectly: true); }\ncatch (ArgumentException) { return resolver.GetFixupToken(names, canAssignDirectly: false); }","preventionTips":["Set canAssignDirectly only for single pending names","Derive the flag from names.Count() == 1","Review custom IXamlNameResolver implementations for hardcoded flags"],"tags":["system-xaml","argument-validation","name-resolution","fixup-token"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}