{"record":{"id":"ef95f29e6baeeb4d","repo":"unoplatform/uno","slug":"specified-static-factory-method-0-for-type-1","errorCode":null,"errorMessage":"Specified static factory method '{0}' for type '{1}' was not found","messagePattern":"Specified static factory method '(.+?)' for type '(.+?)' was not found","errorType":"exception","errorClass":"XamlObjectWriterException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs","lineNumber":350,"sourceCode":"\n\t\t[UnconditionalSuppressMessage(\"Trimming\", \"IL2075\", Justification = \"Types manipulated here have been marked earlier\")]\n\t\tprotected override void OnWriteEndMember ()\n\t\t{\n\t\t\tvar xm = CurrentMember;\n\t\t\tvar state = object_states.Peek ();\n\n\t\t\tif (xm == XamlLanguage.PositionalParameters) {\n\t\t\t\tvar l = (List<object>) state.Value;\n\t\t\t\tstate.Value = escaped_objects.Pop ();\n\t\t\t\tstate.IsInstantiated = true;\n\t\t\t\tPopulateObject (true, l);\n\t\t\t\treturn;\n\t\t\t} else if (xm == XamlLanguage.Arguments) {\n\t\t\t\tif (state.FactoryMethod != null) {\n\t\t\t\t\tvar contents = (List<object>) state.Value;\n\t\t\t\t\tvar mi = state.Type.UnderlyingType.GetMethods (static_flags).FirstOrDefault (mii => mii.Name == state.FactoryMethod && mii.GetParameters ().Length == contents.Count);\n\t\t\t\t\tif (mi == null)\n\t\t\t\t\t\tthrow new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, \"Specified static factory method '{0}' for type '{1}' was not found\", state.FactoryMethod, state.Type));\n\t\t\t\t\tstate.Value = mi.Invoke (null, contents.ToArray ());\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tPopulateObject (false, (List<object>) state.Value);\n\t\t\t\tstate.IsInstantiated = true;\n\t\t\t\tescaped_objects.Pop ();\n\t\t\t} else if (xm == XamlLanguage.Initialization) {\n\t\t\t\t// ... and no need to do anything. The object value to pop *is* the return value.\n\t\t\t} else if (xm == XamlLanguage.Name || xm == state.Type.GetAliasedProperty (XamlLanguage.Name)) {\n\t\t\t\tstring name = (string) CurrentMemberState.Value;\n\t\t\t\tname_scope.RegisterName (name, state.Value);\n\t\t\t} else {\n\t\t\t\tif (xm.IsEvent)\n\t\t\t\t\tSetEvent (xm, (string) CurrentMemberState.Value);\n\t\t\t\telse if (!xm.IsReadOnly) // exclude read-only object such as collection item.\n\t\t\t\t\tSetValue (xm, CurrentMemberState.Value);\n\t\t\t}\n\t\t}","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs#L332-L368","documentation":"Thrown when an object is constructed via x:Arguments combined with x:FactoryMethod and no matching static method is found. The writer searches public static methods (BindingFlags) of the underlying type whose name equals the factory method and whose parameter count equals the supplied arguments. No match yields this exception.","triggerScenarios":"XAML using `<x:Arguments>` with `<x:FactoryMethod>Create</x:FactoryMethod>` where 'Create' does not exist on the type, is not static, is not public, or has a different parameter count than the arguments.","commonSituations":"Factory method renamed or removed; method is an instance method; visibility changed to internal/private; argument count in x:Arguments does not match any overload.","solutions":["Verify the static factory method exists with exactly the same number of parameters as x:Arguments children.","Make the method `public static`.","If no factory method is intended, remove x:FactoryMethod and let x:Arguments drive constructor selection."],"exampleFix":"<!-- before -->\n<Foo>\n  <x:Arguments>\n    <x:String>s</x:String>\n  </x:Arguments>\n  <x:FactoryMethod>Make</x:FactoryMethod>\n</Foo>\n<!-- after: add `public static Foo Make(string s)` to Foo -->","handlingStrategy":"validation","validationCode":"// Before writing, confirm a public static method of the given name and arity exists.\nvar mi = typeof(Foo).GetMethod(\"Create\", BindingFlags.Public | BindingFlags.Static)\n    ?.GetParameters().Length == argCount ? /* ok */ : null;\nif (mi == null)\n    throw new InvalidOperationException(\"No matching static factory method found.\");","typeGuard":null,"tryCatchPattern":"try { writer.WriteStartObject(...); /* x:Arguments + FactoryMethod */ }\ncatch (XamlObjectWriterException ex) when (ex.Message.Contains(\"factory method\")) {\n    // verify the static factory method name, visibility, and parameter count.\n}","preventionTips":["Keep factory methods public static and matched in arity to x:Arguments.","Add a compile-time/test check that factory method signatures exist when using x:FactoryMethod.","If no factory is needed, omit x:FactoryMethod and use x:Arguments for constructor selection."],"tags":["xaml","factory-method","reflection","object-writer"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}