unoplatform/uno · error · InvalidOperationException
ApiExtensionAttribute should takes 2 to 4 arguments.
Error message
ApiExtensionAttribute should takes 2 to 4 arguments.
What it means
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.
Source
Thrown at src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs:717
{
writer.AppendLineIndented($"if (OperatingSystem.IsOSPlatform(\"{registration.ElementAt(3).Value}\"))");
writer.AppendLineIndented("{");
using (writer.Indent())
{
if (registration.ElementAt(3).Value is not null)
{
writer.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));");
}
else
{
writer.AppendLineIndented($"global::Uno.Foundation.Extensibility.ApiExtensibility.Register(typeof(global::{registration.ElementAt(0).Value}), o => new global::{registration.ElementAt(1).Value}(o));");
}
}
writer.AppendLineIndented("}");
}
else
{
throw new InvalidOperationException($"ApiExtensionAttribute should takes 2 to 4 arguments.");
}
}
}
private void InitializeRemoteControlClient(IIndentedStringBuilder writer)
{
if (IsInsideUnoSolution(_generatorContext))
{
// Inside the Uno Solution we do not start the remote control
// client, as the location of the RC server is not coming from
// a nuget package.
writer.AppendLineIndented($"// Automatic remote control startup is disabled");
}
else if (_isHotReloadEnabled)
{
if (_metadataHelper.FindTypeByFullName("Uno.UI.RemoteControl.RemoteControlClient") != null)
{
writer.AppendLineIndented($"global::Uno.UI.RemoteControl.RemoteControlClient.Initialize(GetType());");View on GitHub (pinned to 0418340488)
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.
Example fix
// before [assembly: ApiExtension(typeof(MyType))] // after [assembly: ApiExtension(typeof(MyType), typeof(MyImplementation))]
Defensive patterns
Strategy: validation
Validate before calling
// Verify [ApiExtension] attribute constructor argument count:
// var attrs = typeof(MyAssemblyMarker).Assembly.GetCustomAttributes<ApiExtensionAttribute>();
// foreach (var a in attrs)
// {
// // The constructor must provide 2, 3, or 4 arguments.
// // Inspect: a.TargetType, a.ImplementationType, a.InterfaceType, a.Platform
// } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unable to find 'MethodName' property on '{symbol}'
- MediaPlayerPresenterExtension must be initialized with a Med
- type
- GetTSType: The type {type} is not supported (SpecialType: {t
- GetTSFieldType: The type {type} is not supported (SpecialTyp
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/7bf90c81bb68a6eb.
Report an issue: GitHub.