{"record":{"id":"bb9b01248e7eef0a","repo":"dotnet/wpf","slug":"sr-objectreadernomatchingconstructor","errorCode":null,"errorMessage":"SR.ObjectReaderNoMatchingConstructor","messagePattern":"SR\\.ObjectReaderNoMatchingConstructor","errorType":"exception","errorClass":"XamlObjectReaderException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs","lineNumber":1704,"sourceCode":"                        {\n                            if (!valueXamlType.IsCollection && !valueXamlType.IsDictionary) // always need to serialize items of a collection or dictionary\n                            {\n                                isComplete = true;\n                            }\n                        }\n\n                        break;\n                    }\n                }\n\n                if (member is null && !valueXamlType.UnderlyingType.IsValueType)\n                {\n                    if (ctorArgProps.Count == 0)\n                    {\n                        throw new XamlObjectReaderException(SR.Format(SR.ObjectReaderNoDefaultConstructor, value.GetType()));\n                    }\n\n                    throw new XamlObjectReaderException(SR.Format(SR.ObjectReaderNoMatchingConstructor, value.GetType()));\n                }\n            }\n\n            private static void CheckTypeCanRoundtrip(ObjectMarkupInfo objInfo)\n            {\n                var xamlType = objInfo.XamlNode.XamlType;\n                if (!xamlType.IsConstructible)\n                {\n                    foreach (var property in objInfo.Properties)\n                    {\n                        if (((MemberMarkupInfo)property).IsFactoryMethod && !xamlType.UnderlyingType.IsNested)\n                        {\n                            // this is the case when the class has no public constructor we can use but contains a factory method\n                            // and the class is not nested\n\n                            return;\n                        }\n                    }","sourceCodeStart":1686,"sourceCodeEnd":1722,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs#L1686-L1722","documentation":"XamlObjectReader throws this when a value's type has constructor-argument properties (x:Arguments recorded) but none of the available constructors accept arguments matching what was recorded, and the type also lacks a default-constructor fallback path. It means XAML cannot reconstruct the object with any constructor.","triggerScenarios":"new XamlObjectReader(obj) where a reference type has ctor-argument members but no constructor whose parameters match the recorded argument set (count or types mismatch).","commonSituations":"Constructor signatures changed between assembly versions while object graphs contain instances built with the old signature; x:Arguments supplied in the wrong order or with incompatible types; custom markup extensions emitting wrong-typed arguments.","solutions":["Ensure the type exposes a constructor whose parameter list matches the recorded x:Arguments in count and type","Reorder or re-type x:Arguments to match an actual constructor","Add an explicit constructor accepting the argument types used by the graph","Rebuild the object graph after assembly signature changes"],"exampleFix":"// before: x:Arguments supplies <s:String>, <s:Int32> but ctor is Config(int, string)\n// after: swap argument order\n<s:Arguments><s:Int32>1</s:Int32><s:String>x</s:String></s:Arguments>","handlingStrategy":"validation","validationCode":"bool MatchesSomeCtor(Type t, object[] args) => t.GetConstructors().Any(c => { var ps = c.GetParameters(); return ps.Length == args.Length && ps.Zip(args, (p, a) => p.ParameterType.IsInstanceOfType(a ?? (object)\"\")).All(x => x); });","typeGuard":null,"tryCatchPattern":"try { using var r = new XamlObjectReader(obj); ... } catch (XamlObjectReaderException ex) when (ex.Message.Contains(\"NoMatchingConstructor\")) { /* realign x:Arguments */ }","preventionTips":["Keep x:Arguments order and types aligned with a real constructor","Bump/refresh serialized graphs when constructor signatures change","Add a default constructor as a safe fallback"],"tags":["xaml","constructor","serialization"],"backgroundTag":"invalid-constructor-argument","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"}