{"record":{"id":"9669cd6fb00e0576","repo":"dotnet/wpf","slug":"sr-constructornotfoundforgivenpositionalparameters","errorCode":null,"errorMessage":"SR.ConstructorNotFoundForGivenPositionalParameters","messagePattern":"SR\\.ConstructorNotFoundForGivenPositionalParameters","errorType":"exception","errorClass":"XamlXmlWriterException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs","lineNumber":1923,"sourceCode":"                XamlType objectXamlType = frame.Type;\n                Debug.Assert(objectXamlType is not null);\n\n                Type objectClrType = objectXamlType.UnderlyingType;\n                if (objectClrType is null)\n                {\n                    throw new XamlXmlWriterException(SR.Format(\n                        SR.ExpandPositionalParametersWithoutUnderlyingType, objectXamlType.GetQualifiedName()));\n                }\n\n                int numOfParameters = writer.ppStateInfo.NodesList.Count;\n\n                ParameterInfo[] constructorParameters = GetParametersInfo(objectXamlType, numOfParameters);\n                List<XamlMember> ctorArgProps = GetAllPropertiesWithCAA(objectXamlType);\n\n                // If there aren't the same number of parameters then we throw\n                if (constructorParameters.Length != ctorArgProps.Count)\n                {\n                    throw new XamlXmlWriterException(SR.ConstructorNotFoundForGivenPositionalParameters);\n                }\n\n                for (int i = 0; i < constructorParameters.Length; i++)\n                {\n                    ParameterInfo paraminfo = constructorParameters[i];\n\n                    XamlMember matchingProperty = null;\n                    foreach (var potentialProperty in ctorArgProps)\n                    {\n                        if ((potentialProperty.Type.UnderlyingType == paraminfo.ParameterType) &&\n                            (XamlObjectReader.GetConstructorArgument(potentialProperty) == paraminfo.Name))\n                        {\n                            matchingProperty = potentialProperty;\n                            break;\n                        }\n                    }\n\n                    if (matchingProperty is null)","sourceCodeStart":1905,"sourceCodeEnd":1941,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs#L1905-L1941","documentation":"Positional-parameter expansion matches the supplied argument count to properties decorated with [ConstructorArgument]. If the number of constructor parameters on the CLR type differs from the number of ConstructorArgument properties, no matching constructor exists and XamlXmlWriterException is thrown.","triggerScenarios":"Expanding positional parameters where GetParametersInfo(objectXamlType, n) returns a constructor with m parameters but GetAllPropertiesWithCAA finds a different count of [ConstructorArgument]-attributed properties (count mismatch).","commonSituations":"Markup extension types whose [ConstructorArgument] attributes were added/removed out of sync with the constructor, multiple constructors confusing parameter resolution, third-party extensions with inconsistent metadata.","solutions":["Fix the markup extension type so every constructor parameter has a matching [ConstructorArgument] property (same count).","Remove stale or extra [ConstructorArgument] attributes from properties.","Use a constructor overload whose parameters exactly correspond to the attributed properties.","Catch XamlXmlWriterException and emit explicit x:Arguments nodes instead of relying on expansion."],"exampleFix":"// before\npublic Foo(string a) { ... }\n[ConstructorArgument(\"a\")] public string A { get; }\n[ConstructorArgument(\"b\")] public string B { get; } // extra CAA, no ctor param b\n// after\n[ConstructorArgument(\"a\")] public string A { get; } // only params that exist on ctor","handlingStrategy":"validation","validationCode":"var caaProps = GetAllPropertiesWithCAA(type); if (caaProps.Count != ctorParams.Length) throw new InvalidOperationException(\"ConstructorArgument property count must match constructor parameter count\");","typeGuard":null,"tryCatchPattern":"try { writer.WriteEndObject(); } catch (XamlXmlWriterException ex) when (ex.Message.Contains(\"ConstructorNotFound\")) { /* emit x:Arguments manually */ }","preventionTips":["Keep [ConstructorArgument] attributes in sync with constructors.","Test every markup extension round-trip through XamlXmlWriter.","Avoid overloads that lack full ConstructorArgument coverage."],"tags":["xaml","positional-parameters","constructor"],"backgroundTag":"missing-required-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}