{"record":{"id":"3f8644e50f2264e4","repo":"dotnet/wpf","slug":"xamlxmlwriterexception-sr-xamlxmlwriter","errorCode":null,"errorMessage":"XamlXmlWriterException(SR.ExpandPositionalParametersinTypeWithNoDefaultConstructor)","messagePattern":"XamlXmlWriterException\\(SR\\.ExpandPositionalParametersinTypeWithNoDefaultConstructor\\)","errorType":"exception","errorClass":"XamlXmlWriterException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs","lineNumber":1073,"sourceCode":"                }\n                else\n                {\n                    WriteMemberAsElement(writer);\n                    writer.WriteDeferredNamespaces(XamlNodeType.StartMember);\n                }\n\n                if (property == XamlLanguage.PositionalParameters)\n                {\n                    // the writer is not in a state where it can write markup extensions in curly form\n                    // so it expands the positional parameters as properties.\n\n                    writer.namespaceScopes.Pop();\n\n                    // but in order to expand parameters, the markup extension needs to have a default constructor\n\n                    if (containingType is not null && containingType.ConstructionRequiresArguments)\n                    {\n                        throw new XamlXmlWriterException(SR.ExpandPositionalParametersinTypeWithNoDefaultConstructor);\n                    }\n\n                    writer.ppStateInfo.ReturnState = State;\n                    writer.currentState = ExpandPositionalParameters.State;\n                }\n                else\n                {\n                    writer.currentState = InMember.State;\n                }\n            }\n\n            public override void WriteEndObject(XamlXmlWriter writer)\n            {\n                Debug.Assert(writer.namespaceScopes.Count > 0);\n                Frame frame = writer.namespaceScopes.Pop();\n                if (frame.AllocatingNodeType != XamlNodeType.StartObject &&\n                    frame.AllocatingNodeType != XamlNodeType.GetObject)\n                {","sourceCodeStart":1055,"sourceCodeEnd":1091,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs#L1055-L1091","documentation":"When XamlXmlWriter expands positional parameters of a markup extension into property-element form, it must instantiate the extension type to look up constructor argument names. If the containing type's ConstructionRequiresArguments is true (no default constructor), the expansion cannot proceed, so it throws XamlXmlWriterException ExpandPositionalParametersinTypeWithNoDefaultConstructor.","triggerScenarios":"Writing a markup-extension object that uses positional constructor arguments (x:Arguments style) where the extension's XamlType has ConstructionRequiresArguments == true, triggering ExpandPositionalParameters state.","commonSituations":"Custom markup extensions without a parameterless constructor being serialized; types changed to remove their default constructor in a newer library version; serializers encountering {Extension arg=value} syntax requiring expansion.","solutions":["Add a public parameterless constructor to the markup extension type","Write the extension using explicit named property syntax instead of positional parameters so expansion is unnecessary","Adjust the type's XAML schema/type mapping so ConstructionRequiresArguments is false (e.g. via XamlDeferLoadAttribute or constructor configuration)"],"exampleFix":"// before\nclass MyExt { public MyExt(string a) {...} } // no default ctor, positional args -> throws\n// after\nclass MyExt {\n  public MyExt() {...}\n  public MyExt(string a) {...}\n}","handlingStrategy":"validation","validationCode":"if (extType.ConstructionRequiresArguments) throw new InvalidOperationException($\"{extType.UnderlyingType} needs a default constructor for positional-parameter expansion\");","typeGuard":"bool CanExpandPositionalParams(XamlType t) => t == null || !t.ConstructionRequiresArguments;","tryCatchPattern":"try { writer.WriteNode(reader); }\ncatch (XamlXmlWriterException ex) when (ex.Message.Contains(\"positional\")) { /* fall back to named-property syntax */ }","preventionTips":["Give every custom MarkupExtension a public parameterless constructor","Avoid relying on positional constructor args in serialized XAML","Verify ConstructionRequiresArguments via the schema context in tests"],"tags":["xaml","markup-extension","positional-parameters"],"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-22T01:17:13.364Z"}