{"record":{"id":"28d99a02acc87835","repo":"dotnet/wpf","slug":"xamlschemaexception-sr-format-sr","errorCode":null,"errorMessage":"XamlSchemaException(SR.Format(SR.MarkupExtensionWithDuplicateArity, UnderlyingType, typeVector.Length))","messagePattern":"XamlSchemaException\\(SR\\.Format\\(SR\\.MarkupExtensionWithDuplicateArity, UnderlyingType, typeVector\\.Length\\)\\)","errorType":"exception","errorClass":"XamlSchemaException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs","lineNumber":1711,"sourceCode":"\n            Dictionary<int, IList<XamlType>> ctorDict = new Dictionary<int, IList<XamlType>>();\n            foreach (ConstructorInfo info in GetConstructors())\n            {\n                ParameterInfo[] parameterInfos = info.GetParameters();\n                XamlType[] typeVector = new XamlType[parameterInfos.Length];\n                for (int i = 0; i < parameterInfos.Length; i++)\n                {\n                    ParameterInfo param = parameterInfos[i];\n                    Type type = param.ParameterType;\n                    XamlType xamlType = SchemaContext.GetXamlType(type);\n                    typeVector[i] = xamlType;\n                }\n\n                if (ctorDict.ContainsKey(typeVector.Length))\n                {\n                    if (!SchemaContext.SupportMarkupExtensionsWithDuplicateArity)\n                    {\n                        throw new XamlSchemaException(SR.Format(SR.MarkupExtensionWithDuplicateArity, UnderlyingType, typeVector.Length));\n                    }\n\n                    // Otherwise we just ignore the dupe\n                }\n                else\n                {\n                    ctorDict.Add(typeVector.Length, GetReadOnly(typeVector));\n                }\n            }\n\n            return ctorDict;\n        }\n\n        private bool LookupBooleanValue(BoolTypeBits typeBit)\n        {\n            bool bit;\n            switch (typeBit)\n            {","sourceCodeStart":1693,"sourceCodeEnd":1729,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs#L1693-L1729","documentation":"When computing constructor-based lookup for a markup extension type, XAML allows at most one constructor per arity unless the schema context enables SupportMarkupExtensionsWithDuplicateArity. If two usable constructors share the same parameter count and the feature is disabled, XamlSchemaException MarkupExtensionWithDuplicateArity is thrown.","triggerScenarios":"Using a markup extension class that defines two constructors with the same number of parameters (e.g. ctor(string) and ctor(Type)) in XAML markup extension resolution, while the XamlSchemaContext has SupportMarkupExtensionsWithDuplicateArity == false (the default).","commonSituations":"Custom markup extensions with convenience overloads used inside XAML; moving markup extensions from environments where duplicate arity was enabled to default contexts; adding an overload to an existing extension that previously had unique arities.","solutions":["Remove or consolidate constructors so each arity appears at most once (e.g. chain one ctor to another with defaults)","Enable duplicate arity on the schema context: new XamlSchemaContext(null, new XamlSchemaContextSettings { SupportMarkupExtensionsWithDuplicateArity = true })","Mark the less-specific constructor non-public or add a distinguishing parameter"],"exampleFix":"// before\npublic MyExtension(string s) { ... }\npublic MyExtension(Type t) { ... }  // duplicate arity 1\n// after\npublic MyExtension(string s) { ... }\npublic MyExtension(Type t, int extra) { ... }  // distinct arities\n// or: new XamlSchemaContext(null, new XamlSchemaContextSettings { SupportMarkupExtensionsWithDuplicateArity = true })","handlingStrategy":"try-catch","validationCode":"var ctorArities = typeof(MyExtension).GetConstructors().Select(c => c.GetParameters().Length);\nbool hasDuplicateArity = ctorArities.GroupBy(a => a).Any(g => g.Count() > 1);","typeGuard":null,"tryCatchPattern":"try { var t = schemaContext.GetXamlType(meType); }\ncatch (XamlSchemaException ex) when (ex.Message.Contains(\"arity\")) { /* enable duplicate arity or fix ctors */ }","preventionTips":["Design markup extensions with unique constructor arities","Enable SupportMarkupExtensionsWithDuplicateArity when overloads are required","Test custom markup extensions against default XamlSchemaContext settings"],"tags":["markupextension","schema-exception","constructor-arity","xaml"],"backgroundTag":"schema-validation-failed","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"}