{"record":{"id":"7bf90c81bb68a6eb","repo":"unoplatform/uno","slug":"apiextensionattribute-should-takes-2-to-4-argument","errorCode":null,"errorMessage":"ApiExtensionAttribute should takes 2 to 4 arguments.","messagePattern":"ApiExtensionAttribute should takes 2 to 4 arguments\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs","lineNumber":717,"sourceCode":"\t\t\t\t{\n\t\t\t\t\twriter.AppendLineIndented($\"if (OperatingSystem.IsOSPlatform(\\\"{registration.ElementAt(3).Value}\\\"))\");\n\t\t\t\t\twriter.AppendLineIndented(\"{\");\n\t\t\t\t\tusing (writer.Indent())\n\t\t\t\t\t{\n\t\t\t\t\t\tif (registration.ElementAt(3).Value is not null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\twriter.AppendLineIndented($\"global::Uno.Foundation.Extensibility.ApiExtensibility.Register<global::{registration.ElementAt(2).Value}>(typeof(global::{registration.ElementAt(0).Value}), o => new global::{registration.ElementAt(1).Value}(o));\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\twriter.AppendLineIndented($\"global::Uno.Foundation.Extensibility.ApiExtensibility.Register(typeof(global::{registration.ElementAt(0).Value}), o => new global::{registration.ElementAt(1).Value}(o));\");\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\twriter.AppendLineIndented(\"}\");\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tthrow new InvalidOperationException($\"ApiExtensionAttribute should takes 2 to 4 arguments.\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate void InitializeRemoteControlClient(IIndentedStringBuilder writer)\n\t\t{\n\t\t\tif (IsInsideUnoSolution(_generatorContext))\n\t\t\t{\n\t\t\t\t// Inside the Uno Solution we do not start the remote control\n\t\t\t\t// client, as the location of the RC server is not coming from \n\t\t\t\t// a nuget package.\n\t\t\t\twriter.AppendLineIndented($\"// Automatic remote control startup is disabled\");\n\t\t\t}\n\t\t\telse if (_isHotReloadEnabled)\n\t\t\t{\n\t\t\t\tif (_metadataHelper.FindTypeByFullName(\"Uno.UI.RemoteControl.RemoteControlClient\") != null)\n\t\t\t\t{\n\t\t\t\t\twriter.AppendLineIndented($\"global::Uno.UI.RemoteControl.RemoteControlClient.Initialize(GetType());\");","sourceCodeStart":699,"sourceCodeEnd":735,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs#L699-L735","documentation":"Thrown by GenerateApiExtensionRegistrations when an [ApiExtension] (ApiExtensionAttribute) constructor on an assembly has a number of arguments that is not 2, 3, or 4. The method handles 2 args (type + impl), 3 args (type + impl + interface), and 4 args (type + impl + interface + platform), and throws for anything else.","triggerScenarios":"An assembly-level [ApiExtension] attribute is declared with 0, 1, 5, or more constructor arguments, or the attribute constructor signature changed and the existing usage no longer matches the expected 2–4 argument range.","commonSituations":"A platform extensibility assembly was authored with an incorrect [ApiExtension] declaration; the attribute definition was modified but existing usages were not updated; a hand-written assembly attribute was malformed.","solutions":["Ensure the [ApiExtension] attribute has exactly 2, 3, or 4 constructor arguments.","Follow the existing pattern: [assembly: ApiExtension(typeof(TargetType), typeof(ImplementationType))] for 2 args.","Add the optional interface type as the 3rd arg and platform string as the 4th arg if needed.","Check the ApiExtensionAttribute constructor definition for the expected parameter order."],"exampleFix":"// before\n[assembly: ApiExtension(typeof(MyType))]\n// after\n[assembly: ApiExtension(typeof(MyType), typeof(MyImplementation))]","handlingStrategy":"validation","validationCode":"// Verify [ApiExtension] attribute constructor argument count:\n// var attrs = typeof(MyAssemblyMarker).Assembly.GetCustomAttributes<ApiExtensionAttribute>();\n// foreach (var a in attrs)\n// {\n//     // The constructor must provide 2, 3, or 4 arguments.\n//     // Inspect: a.TargetType, a.ImplementationType, a.InterfaceType, a.Platform\n// }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Follow the 2/3/4-argument pattern when declaring [assembly: ApiExtension(...)].","Copy from an existing working ApiExtension declaration in the codebase.","Check the ApiExtensionAttribute constructor definition for expected parameters."],"tags":["api-extension","extensibility","source-generator","attribute"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}