{"record":{"id":"f42e9d173e4b30a8","repo":"dotnet/wpf","slug":"sr-objectreaderinstancedescriptorinvalidmethod","errorCode":null,"errorMessage":"SR.ObjectReaderInstanceDescriptorInvalidMethod","messagePattern":"SR\\.ObjectReaderInstanceDescriptorInvalidMethod","errorType":"exception","errorClass":"XamlObjectReaderException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs","lineNumber":1267,"sourceCode":"                    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)\n                    {\n                        var parameterInfo = methodParams[argPos++];\n                        if (argument is null)\n                        {\n                            if (parameterInfo.ParameterType.IsValueType)\n                            {\n                                if (!(parameterInfo.ParameterType.IsGenericType &&","sourceCodeStart":1249,"sourceCodeEnd":1285,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs#L1249-L1285","documentation":"AddFactoryMethodAndValidateArguments must resolve a constructor or factory method to hold the instance's construction arguments. When the InstanceDescriptor's MemberInfo is neither a ConstructorInfo, a MethodInfo, nor absent (default-ctor path), and the value type is not a struct handled above, the reader cannot represent the construction and throws XamlObjectReaderException.","triggerScenarios":"Reading an instance whose InstanceDescriptor.MemberInfo is a non-invocable member (FieldInfo, PropertyInfo, EventInfo) for a reference type — the final else branch at XamlObjectReader.cs:1265-1267.","commonSituations":"Custom TypeConverters building InstanceDescriptor from a static field or property; third-party types whose converters were written for other serializers; assembly trimming/mismatch making the expected constructor unavailable so only a field member remains.","solutions":["Fix the TypeConverter's ConvertTo(ITypeDescriptorContext, InstanceDescriptor) to return a ConstructorInfo or static MethodInfo member.","If the value truly uses default construction, return an InstanceDescriptor with a null MemberInfo and empty arguments.","Update/replace the third-party converter with one compatible with System.Xaml's XamlSchemaContext."],"exampleFix":"// before\nreturn new InstanceDescriptor(typeof(MyType).GetField(\"Instance\"), Array.Empty<object>());\n// after\nvar ctor = typeof(MyType).GetConstructor(Type.EmptyTypes);\nreturn new InstanceDescriptor(ctor, null, true);","handlingStrategy":"type-guard","validationCode":"static void ValidateDescriptor(InstanceDescriptor d) {\n  if (d?.MemberInfo is not null && d.MemberInfo is not (ConstructorInfo or MethodInfo))\n    throw new InvalidOperationException(\"InstanceDescriptor member must be a ctor or method.\");\n}","typeGuard":"bool HasInvocableMember(InstanceDescriptor d) => d?.MemberInfo is null or ConstructorInfo or MethodInfo;\n","tryCatchPattern":"try { using var r = new XamlObjectReader(instance); }\ncatch (XamlObjectReaderException ex) when (ex.Message.Contains(\"InvalidMethod\")) { /* fix converter or use default ctor */ }","preventionTips":["Only return ConstructorInfo/MethodInfo from InstanceDescriptor converters.","Test custom converters with XamlObjectReader, not just PropertyDescriptor-based serializers.","Watch for trimming removing the expected constructor."],"tags":["xaml","instancedescriptor","invalid-argument-value"],"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-21T21:30:21.729Z"}