thorium-cfx / mono_v2_get_started

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

Server events handlers invocation error #29

Closed Marky-S closed 1 year ago

Marky-S commented 1 year ago

What happened?

Can't handle server event onResourceStop

[script:core] SCRIPT ERROR: Could not invoke event handler Server.Entry.OnResourceStop
[script:core]   expected: (String)
[script:core]   received: (String)
[script:core]   * Any type in red is not convertible, castable, or simply missing and requires attention.
[script:core] Failed with exception:
[script:core] System.InvalidCastException: Specified cast is not valid.
[script:core]   at Server.Entry.OnResourceStop (System.String resourceName) [0x0001f] in <5d7676cd4bf444b5b52837e7dc51f3c1>:0 
[script:core]   at (wrapper dynamic-method) System.Object.Server.Entry.OnResourceStop(CitizenFX.Core.Remote,object[])
[script:core]   at (wrapper delegate-invoke) <Module>.invoke_object_Remote_object[](CitizenFX.Core.Remote,object[])
[script:core]   at CitizenFX.Core.EventsManager.IncomingEvent (System.String eventName, System.String sourceString, CitizenFX.Core.Binding origin, System.Byte* argsSerialized, System.Int32 serializedSize, System.Object[] args) [0x00049] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore-v2\Interop\EventsManager.cs:35 

There is a code:

[EventHandler("onResourceStop")]
private static void OnResourceStop(string resourceName)

Expected result

Correct method invocation

Reproduction steps

No need.

Importancy

Can't use this feature until fixed

Specific version

No response

Extra

No response

thorium-cfx commented 1 year ago

Your repro steps are a tad off ;) You also put the (minimal needed) code there to reproduce.

On that note, this works fine:

[EventHandler("onResourceStop")]
private static void OnResourceStop(string resourceName)
{
    Debug.WriteLine($"Resource {resourceName} stopped");
}

Looking at your error, it seems like you're casting something else in your method that's not working out.

Closing this as it seems to be a user error, but we can reopen it when we're able to reproduce it.