[C#] TriggerClientEvent


#1

Hi,

I thought I had the same problem as this post : [C#] TriggerClientEvent crashes resources intermittently, but unfortunately, I have the same problem.

Here’s the part of the code that gets the server to crash :

private async void buyVehicule([FromSource]Player player, int id_veh, int price)
(...)
            else
            {
                Debug.WriteLine("test"); //<<<---- this is ok
                TriggerClientEvent(player, "notif", "test1-2");  //<<<---- this is NOT ok
            }

and on the client (lua file, other resource)

RegisterNetEvent('notif')
AddEventHandler('notif', function(msg)
	sendnotif(msg)
end)

Here’s the console error :

InvokeNative: execution failed: No current resource manager.
Unhandled exception: System.ArgumentException: Value does not fall within the expected range.


Server stack trace:
  at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR (System.Int32 errorCode) [0x0000a] in <fb0d2884a2b44d8db375bbed7cc70740>:0
  at (wrapper cominterop) CitizenFX.Core.IScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)
  at (wrapper cominterop-invoke) CitizenFX.Core.IScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)
  at CitizenFX.Core.MonoScriptRuntime+WrapScriptHost.InvokeNative (CitizenFX.Core.fxScriptContext& context) [0x00000] in /src/code/client/clrcore/MonoScriptRuntime.cs:242
  at (wrapper remoting-invoke-with-check) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)
  at (wrapper xdomain-dispatch) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (object,byte[]&,byte[]&)

Exception rethrown at [0]:
  at (wrapper xdomain-invoke) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)
  at CitizenFX.Core.ScriptContext.InvokeInternal (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x0000c] in /src/code/client/clrcore/ScriptContext.cs:173
  at CitizenFX.Core.ScriptContext.Invoke (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x00000] in /src/code/client/clrcore/ScriptContext.cs:166
  at CitizenFX.Core.Native.Function.InvokeInternal (CitizenFX.Core.Native.Hash nativeHash, System.Type returnType, CitizenFX.Core.Native.InputArgument[] args) [0x00026] in /src/code/client/clrcore/Native.cs:28
  at CitizenFX.Core.Native.Function.Call (CitizenFX.Core.Native.Hash hash, CitizenFX.Core.Native.InputArgument[] arguments) [0x00000] in /src/code/client/clrcore/Native.cs:16
  at CitizenFX.Core.Player.TriggerEvent (System.String eventName, System.Object[] args) [0x0000f] in /src/code/client/clrcore/Server/ServerWrappers.cs:47
  at vehShopSv.vehShopSv+<achatVehicule>d__6.MoveNext () [0x002ae] in <e73b5c81d55842b598be0d5c0cfa09b9>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <fb0d2884a2b44d8db375bbed7cc70740>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1 (System.Object state) [0x00000] in <fb0d2884a2b44d8db375bbed7cc70740>:0
  at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x00007] in <fb0d2884a2b44d8db375bbed7cc70740>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <fb0d2884a2b44d8db375bbed7cc70740>:0
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <fb0d2884a2b44d8db375bbed7cc70740>:0
  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00021] in <fb0d2884a2b44d8db375bbed7cc70740>:0
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <fb0d2884a2b44d8db375bbed7cc70740>:0
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <fb0d2884a2b44d8db375bbed7cc70740>:0
GlobalError: Unhandled exception in Mono script environment: System.ArgumentException: Value does not fall within the expected range.
...

And then the server crashes.

I’m working on VS2017, .NET4.5.2, I use the latest CitizenFX.Core.dll and the server runs on Ubuntu. It was restared, and the cache was cleared.
I also tried using player.TriggerEvent(“notif”,“blalba”), but same consequences…

Thank you in advance for your cooperation and pardon me if I’m in the wrong forum category.

Regards,


C# TriggerClientEvent "No current resource manager."
Please post some c# code snippets
#2

when exactly are you calling this function what are you doing


#3

not a bug, you’re probably doing something in your method that makes it get scheduled on another thread


#4

My mitsake then, feel free to move the topic to technical issues

The code looks like that :

using CitizenFX.Core;
using MySql.Data.MySqlClient;
using System;
using System.Threading.Tasks;

namespace vehShopSv
{
   public vehShopSv()
        {
            Debug.WriteLine("vehShopSv Ok");
            EventHandlers.Add("buyVehicle", new Action<Player, int, int>(buyVehicle));
        }

   private async void buyVehicle([FromSource]Player player, int id_veh, int price)
        {
            Debug.WriteLine("Player : " + player.Name);
            Bank = await CheckBankAsync(GetIDFromPlayer(player)); //GetIDFromPlayer(player) value is correct
            if (Bank >= price) //bank value is correct when printed
            {
                 //no pb here
            }
            else
                 TriggerClientEvent(player, "notif", "test1-2"); //when this is triggered, I get the error and then the server crashes
         }
}

I have to admit, I have absolutely no idea where I am doing something wrong :confused:

Thanks in advance for your help !


#5

Changed

TriggerClientEvent(player, "notif", "test1-2");

into

                string test = "test1-2";
                TriggerClientEvent(player, "notif", new object[1]
                {
                    (object) test
                });

Problem solved.

Enjoy


#6

Seems like weird shit nevertheless.


#7

Indeed… But ¯_(ツ)_/¯


#8

I tried your solution with my code, and I get the same crash, but I am also trying to trigger it on all clients, not just one. Ughhh. I can’t figure this crap out.


#9

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.