{"record":{"id":"d076fd357c676a6c","repo":"dotnet/wpf","slug":"sr-expandpositionalparameterswithoutunderlyingtype","errorCode":null,"errorMessage":"SR.ExpandPositionalParametersWithoutUnderlyingType (objectXamlType.GetQualifiedName())","messagePattern":"SR\\.ExpandPositionalParametersWithoutUnderlyingType \\(objectXamlType\\.GetQualifiedName\\(\\)\\)","errorType":"exception","errorClass":"XamlXmlWriterException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs","lineNumber":1911,"sourceCode":"            private ExpandPositionalParameters() { }\n\n            public static WriterState State\n            {\n                get { return state; }\n            }\n\n            private void ExpandPositionalParametersIntoProperties(XamlXmlWriter writer)\n            {\n                Frame frame = writer.namespaceScopes.Peek();\n                Debug.Assert(frame.AllocatingNodeType == XamlNodeType.StartObject);\n\n                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","sourceCodeStart":1893,"sourceCodeEnd":1929,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlXmlWriter.cs#L1893-L1929","documentation":"When expanding positional parameters (x:Arguments-style markup extension nodes), the writer needs the CLR type of the object to inspect constructor parameters. If the XamlType has no UnderlyingType, XamlXmlWriterException is thrown because expansion cannot proceed without reflection over the actual CLR type.","triggerScenarios":"Closing a StartObject whose XamlType.UnderlyingType is null while positional-parameter expansion is active — typically types from a schema context without CLR type mapping (type-only schema contexts, forwarded/unloaded types).","commonSituations":"Using XamlSchemaContext without an assembly resolver so referenced types can't be loaded, serializing XAML for types in not-yet-referenced assemblies, markup extensions whose types come from a metadata-only context.","solutions":["Ensure the XamlSchemaContext can resolve the type's CLR type (reference the assembly, use AssemblyLoadContext/assembly resolvers).","Use a schema context with type mapping (e.g. XamlSchemaContext with reference assemblies) instead of a bare context.","Avoid positional-parameter expansion for unknown types by writing explicit x:Arguments members.","Catch XamlXmlWriterException and fall back to non-expanded node output."],"exampleFix":"// before\nvar sc = new XamlSchemaContext(); // cannot resolve underlying types\n// after\nvar sc = new XamlSchemaContext(new[] { typeof(MyExtension).Assembly });","handlingStrategy":"type-guard","validationCode":"if (objectXamlType.UnderlyingType is null) throw new InvalidOperationException(\"Cannot expand positional parameters without a CLR underlying type\");","typeGuard":"bool CanExpand(XamlType t) => t?.UnderlyingType is not null;","tryCatchPattern":"try { writer.Close(); } catch (XamlXmlWriterException ex) when (ex.Message.Contains(\"UnderlyingType\")) { /* serialize without pp expansion */ }","preventionTips":["Provide assembly references/resolvers to XamlSchemaContext.","Verify UnderlyingType before enabling positional-parameter expansion.","Prefer explicit x:Arguments for types loaded dynamically."],"tags":["xaml","positional-parameters","missing-dependency"],"backgroundTag":"missing-dependency","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"}