SDT1306: Misplaced RmlEvent Parameter

Property Value
Rule ID SDT1306
Title Misplaced RmlEvent Parameter
Category UI
Severity Error

Cause

A method decorated with [RmlDataEvent] declares an RmlEvent parameter in a position other than the first parameter.

Rule Description

When RmlUi dispatches events to [RmlDataEvent] methods, it optionally supplies the raw event context (RmlEvent). The invocation convention mandates that if RmlEvent is included in the parameter list, it must be the first parameter (index == 0). Any subsequent parameters are unpacked from arguments defined in the UI markup (e.g. data-event-click="OnSelect(item.id)").

Placing RmlEvent after other parameters disrupts argument deserialization and causes invocation errors.

How to Fix Violations

Move the RmlEvent parameter to the first position, or remove it entirely if the event context is not needed.

Violation:

public sealed class MenuModel(RmlDataModelToken token) : RmlDataModel(token)
{
    [RmlDataEvent]
    public void OnItemSelected(int id, RmlEvent @event)
    {
        // ...
    }
}

Fix:

public sealed class MenuModel(RmlDataModelToken token) : RmlDataModel(token)
{
    [RmlDataEvent]
    public void OnItemSelected(RmlEvent @event, int id)
    {
        // ...
    }
}

When to Suppress Warnings

Danger

Do not suppress this error. Misplaced RmlEvent parameters prevent the RmlUi dispatcher from matching and unpacking event parameters at runtime, preventing the event from firing.