{"record":{"id":"63076cd8cde4b4ee","repo":"dotnet/wpf","slug":"sr-objectreaderinstancedescriptorincompatiblearguments","errorCode":null,"errorMessage":"SR.ObjectReaderInstanceDescriptorIncompatibleArguments","messagePattern":"SR\\.ObjectReaderInstanceDescriptorIncompatibleArguments","errorType":"exception","errorClass":"XamlObjectReaderException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs","lineNumber":1260,"sourceCode":"                    var declaringType = memberInfo.DeclaringType;\n                    if (declaringType != valueType)\n                    {\n                        methodName = ConvertTypeAndMethodToString(declaringType, methodName, context);\n                    }\n\n                    // add factory method if there is one\n                    Properties.Add(new MemberMarkupInfo\n                    {\n                        XamlNode = new XamlNode(XamlNodeType.StartMember, XamlLanguage.FactoryMethod),\n                        IsFactoryMethod = true,\n                        Children = { new ValueMarkupInfo() { XamlNode = new XamlNode(XamlNodeType.Value, methodName) } }\n                    });\n                }\n                else if (valueType.IsValueType)\n                {\n                    if (arguments is not null && arguments.Count > 0)\n                    {\n                        throw new XamlObjectReaderException(SR.ObjectReaderInstanceDescriptorIncompatibleArguments);\n                    }\n\n                    return;\n                }\n                else\n                {\n                    throw new XamlObjectReaderException(SR.ObjectReaderInstanceDescriptorInvalidMethod);\n                }\n\n                if (arguments is not null)\n                {\n                    if (arguments.Count != methodParams.Length)\n                    {\n                        throw new XamlObjectReaderException(SR.ObjectReaderInstanceDescriptorIncompatibleArguments);\n                    }\n\n                    int argPos = 0;\n                    foreach (var argument in arguments)","sourceCodeStart":1242,"sourceCodeEnd":1278,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs#L1242-L1278","documentation":"When reconstructing XAML for a value type instance whose InstanceDescriptor supplied factory arguments, the reader must have a constructor/factory method to apply them to. For a value type with no matching constructor/factory member, positional arguments cannot be represented, so XamlObjectReaderException is thrown.","triggerScenarios":"Reading a value-type instance obtained through an InstanceDescriptor whose MemberInfo is not a constructor/method (e.g. a field/property member) while the descriptor's Arguments collection is non-empty — AddFactoryMethodAndValidateArguments, valueType.IsValueType branch (XamlObjectReader.cs:1256-1261).","commonSituations":"Custom TypeConverter.GetCreateInstanceDescriptor returning a descriptor whose member is a property/field with arguments; structs exposed through converters that try to pass constructor arguments via a non-constructor member; serialization of custom structs with required constructor parameters.","solutions":["Return an InstanceDescriptor whose MemberInfo is a ConstructorInfo (or static factory MethodInfo) for value types, matching the argument list.","If the descriptor intentionally uses a field/property member, supply an empty Arguments collection.","Change the struct to expose a parameterless constructor and set properties, avoiding constructor arguments in the descriptor."],"exampleFix":"// before\nreturn new InstanceDescriptor(typeof(MyStruct).GetField(\"Default\"), new object[] { 1, 2 }); // field member with args\n// after\nvar ctor = typeof(MyStruct).GetConstructor(new[] { typeof(int), typeof(int) });\nreturn new InstanceDescriptor(ctor, new object[] { 1, 2 }); // ctor matches argument count","handlingStrategy":"type-guard","validationCode":"static void ValidateDescriptor(InstanceDescriptor d) {\n  if (d?.MemberInfo is ConstructorInfo or MethodInfo) return;\n  if (d?.Arguments is { Count: > 0 }) throw new InvalidOperationException(\"Non-ctor member with arguments is not serializable.\");\n}","typeGuard":"bool IsValidValueDescriptor(InstanceDescriptor d) => d?.MemberInfo is ConstructorInfo or MethodInfo or null;\n","tryCatchPattern":"try { using var r = new XamlObjectReader(instance); }\ncatch (XamlObjectReaderException ex) when (ex.Message.Contains(\"IncompatibleArguments\")) { /* fix the TypeConverter's InstanceDescriptor */ }","preventionTips":["Return ConstructorInfo members from ConvertTo(InstanceDescriptor) for structs.","Keep descriptor arguments empty when using field/property members.","Unit-test custom TypeConverters via XamlServices round-trips."],"tags":["xaml","instancedescriptor","value-type"],"backgroundTag":"invalid-argument-value","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"}