thorium-cfx / mono_v2_get_started

Mono v2 runtime for FiveM/RedM
36 stars 3 forks source link

Remote event argument type affects the call of the handler #30

Closed Marky-S closed 1 year ago

Marky-S commented 1 year ago

What happened?

I created remote event from client to server with arguments like [uint modelHash, string modelType] and received this error:

SCRIPT ERROR: Could not invoke event handler Action
[script:core]   expected: (CitizenFX.Core.Remote, Object[])
[script:core]   received: (UInt32               , String  )

Expected result

Correct event handling

Reproduction steps

  1. Trigger server event from client with first uint arg
    // ...client... //
    Events.TriggerServerEvent("myEvent", modelHash, modelType); // args [uint, string]
  2. Handle this event on server with DynFunc delegate
    
    // ...server... //
    EventHandlers["myEvent"].Add(wrapperInstance.Action, Binding.All);

// ...wrapper instance class... // public object Action(Remote remote, params object[] args)


### Importancy

Slight inconvenience

### Specific version

_No response_

### Extra

After some research I was able to solve this problem simply by changing the type of the first argument from `uint` to  `int` and code above works fine.
```csharp
// ...client... //
Events.TriggerServerEvent("myEvent", (int)modelHash, modelType);
thorium-cfx commented 1 year ago

I'm unable to reproduce it with the given repro steps, the int version also doesn't make sense in this context. Can you supply more of the error and code on this? Especially what you run in the Action method.

Do note that the error helper (expected & received info) only applies for wrappers, i.e.: any made through Func.Create, therefore its information is useless on non-wrappers, like the ones you use now.

Marky-S commented 1 year ago

Yeah, second time there was a mistake in my wrapper-method.

I always get confused with the error context because of this part of the exception:

[script:core] SCRIPT ERROR: Could not invoke event handler Action
[script:core]   expected: (CitizenFX.Core.Remote, Object[])
[script:core]   received: (UInt32               , String  )
[script:core]   * Any type in red is not convertible, castable, or simply missing and requires attention.

expected and received fields both contained red arguments.

I'll be more attentive in the future