C# TriggerClientEvent "No current resource manager."

I am having the same exact problem as this post. I hate to create a new topic for this, but that was marked as solved and its likely nobody will read it. The solution provided in that post does not work for me.


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

[     79046] 

[     79061] 

[     79061] Server stack trace: 

[     79061]   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR (System.Int32 errorCode) [0x0000a] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79061]   at (wrapper cominterop) CitizenFX.Core.IScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79077]   at (wrapper cominterop-invoke) CitizenFX.Core.IScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79077]   at CitizenFX.Core.MonoScriptRuntime+WrapScriptHost.InvokeNative (CitizenFX.Core.fxScriptContext& context) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\MonoScriptRuntime.cs:242 

[     79077]   at (wrapper remoting-invoke-with-check) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79077]   at (wrapper xdomain-dispatch) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (object,byte[]&,byte[]&)

[     79077] 

[     79092] Exception rethrown at [0]: 

[     79092]   at (wrapper xdomain-invoke) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79092]   at CitizenFX.Core.ScriptContext.InvokeInternal (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x0000c] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\ScriptContext.cs:173 

[     79092]   at CitizenFX.Core.ScriptContext.Invoke (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\ScriptContext.cs:166 

[     79108]   at CitizenFX.Core.Native.Function.InvokeInternal (CitizenFX.Core.Native.Hash nativeHash, System.Type returnType, CitizenFX.Core.Native.InputArgument[] args) [0x00026] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\Native.cs:28 

[     79108]   at CitizenFX.Core.Native.Function.Call (CitizenFX.Core.Native.Hash hash, CitizenFX.Core.Native.InputArgument[] arguments) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\Native.cs:16 

[     79108]   at CitizenFX.Core.BaseScript.TriggerClientEvent (System.String eventName, System.Object[] args) [0x00012] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\BaseScript.cs:133 

[     79108]   at BrigSteamScoreBoardSV.BrigSteamScoreBoardSV+<ScoreboardJoined>d__11.MoveNext () [0x00302] in <8a32d18219be4c6096a01937759c7d7d>:0 

[     79108] --- End of stack trace from previous location where exception was thrown ---

[     79124]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79124]   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1 (System.Object state) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79124]   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x00007] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79124]   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79124]   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79139]   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00021] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79139]   at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79139]   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 
[     79342] GlobalError: Unhandled exception in Mono script environment: System.ArgumentException: Value does not fall within the expected range.

[     79342] 

[     79342] 

[     79342] Server stack trace: 

[     79358]   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR (System.Int32 errorCode) [0x0000a] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79358]   at (wrapper cominterop) CitizenFX.Core.IScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79358]   at (wrapper cominterop-invoke) CitizenFX.Core.IScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79358]   at CitizenFX.Core.MonoScriptRuntime+WrapScriptHost.InvokeNative (CitizenFX.Core.fxScriptContext& context) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\MonoScriptRuntime.cs:242 

[     79358]   at (wrapper remoting-invoke-with-check) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79373]   at (wrapper xdomain-dispatch) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (object,byte[]&,byte[]&)

[     79373] 

[     79373] Exception rethrown at [0]: 

[     79373]   at (wrapper xdomain-invoke) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79389]   at CitizenFX.Core.ScriptContext.InvokeInternal (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x0000c] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\ScriptContext.cs:173 

[     79389]   at CitizenFX.Core.ScriptContext.Invoke (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\ScriptContext.cs:166 

[     79389]   at CitizenFX.Core.Native.Function.InvokeInternal (CitizenFX.Core.Native.Hash nativeHash, System.Type returnType, CitizenFX.Core.Native.InputArgument[] args) [0x00026] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\Native.cs:28 

[     79389]   at CitizenFX.Core.Native.Function.Call (CitizenFX.Core.Native.Hash hash, CitizenFX.Core.Native.InputArgument[] arguments) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\Native.cs:16 

[     79404]   at CitizenFX.Core.BaseScript.TriggerClientEvent (System.String eventName, System.Object[] args) [0x00012] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\BaseScript.cs:133 

[     79420]   at BrigSteamScoreBoardSV.BrigSteamScoreBoardSV+<ScoreboardJoined>d__11.MoveNext () [0x00302] in <8a32d18219be4c6096a01937759c7d7d>:0 

[     79436] --- End of stack trace from previous location where exception was thrown ---

[     79436]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79436]   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1 (System.Object state) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79436]   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x00007] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79436]   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79451]   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79451]   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00021] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79451]   at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79451]   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0  

[     79467] 

[     79467] Server stack trace: 

[     79467]   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR (System.Int32 errorCode) [0x0000a] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79467]   at (wrapper cominterop) CitizenFX.Core.IScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79467]   at (wrapper cominterop-invoke) CitizenFX.Core.IScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79482]   at CitizenFX.Core.MonoScriptRuntime+WrapScriptHost.InvokeNative (CitizenFX.Core.fxScriptContext& context) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\MonoScriptRuntime.cs:242 

[     79482]   at (wrapper remoting-invoke-with-check) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79482]   at (wrapper xdomain-dispatch) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (object,byte[]&,byte[]&)

[     79482] 

[     79482] Exception rethrown at [0]: 

[     79498]   at (wrapper xdomain-invoke) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost:InvokeNative (CitizenFX.Core.fxScriptContext&)

[     79498]   at CitizenFX.Core.ScriptContext.InvokeInternal (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x0000c] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\ScriptContext.cs:173 

[     79514]   at CitizenFX.Core.ScriptContext.Invoke (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\ScriptContext.cs:166 

[     79514]   at CitizenFX.Core.Native.Function.InvokeInternal (CitizenFX.Core.Native.Hash nativeHash, System.Type returnType, CitizenFX.Core.Native.InputArgument[] args) [0x00026] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\Native.cs:28 

[     79514]   at CitizenFX.Core.Native.Function.Call (CitizenFX.Core.Native.Hash hash, CitizenFX.Core.Native.InputArgument[] arguments) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\Native.cs:16 

[     79514]   at CitizenFX.Core.BaseScript.TriggerClientEvent (System.String eventName, System.Object[] args) [0x00012] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\BaseScript.cs:133 

[     79514]   at BrigSteamScoreBoardSV.BrigSteamScoreBoardSV+<ScoreboardJoined>d__11.MoveNext () [0x00302] in <8a32d18219be4c6096a01937759c7d7d>:0 

[     79529] --- End of stack trace from previous location where exception was thrown ---

[     79529]   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79529]   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1 (System.Object state) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79529]   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x00007] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79545]   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79545]   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79545]   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00021] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79545]   at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

[     79560]   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <0123fd5b1a1040fe9d70a7e0d4b28acb>:0 

This is the function in question. This is being triggered by the client when NetworkIsSessionStarted() becomes true, basically right as the player spawns.

public async void ScoreboardJoined([FromSource] Player ply)
{
    string plySteam = ply.Identifiers["steam"];
    string avURL = "NONE";

    if (plySteam != null)
    {
        ...Get info using HttpClient...
    }
    else
    {
        ...
    }

    ScoreBoardPlayer temp = new ScoreBoardPlayer();
    temp.AvURL = avURL;
    temp.SteamID = plySteam;

    scoreboardPlayers.Add(int.Parse(ply.Handle), temp);

    await Delay(5000); // Prevent crash on join
    
    int plyHand = int.Parse(ply.Handle);
    TriggerClientEvent("scoreboardAdd", plyHand, temp); // ** CRASH HERE **

    ...
}

I have put in an await Delay(5000); as a temporary work-around, which has worked, but if the player is still not fully spawned in (on really slow computers) the server will crash with the error above. If the player is spawned in before this triggers, nothing is wrong.

I am 100% lost with this, and I have no alternative (that I know of). I need to fetch info as a client joins and then send it to everybody.

I feel you, I was going to answer on my previous post. Only fix I could find is the same as you, adding a delay. 100ms seem to be enough for me, on small Async SQL Queries in my case.

Still looking for help if anyone has a more precise idea of the problem.

@QuentinS, Is your function being triggered right on player join (like mine), or at some other time?

No it’s triggered during gameplay, way after player is spawned

here’s your issue, httpclient’s task return value is from the CLR itself and therefore gets executed in the threadpool

delay will only be executed on the main thread so - if it works - is a valid workaround to marshal back to the main thread, even 0ms would be fine, it’ll execute next server tick like that

I understand that if it is on a different thread, then it will cause issues, but this only crashes when triggered on someone who has not fully connected/spawned yet.

I also have the delay in there, but if the delay isn’t great enough, a person who takes longer to load in will crash the server.

highly doubtful that is related, even 0 delay should be perfectly fine with regards to this specific error

anything more specific to repro than a half-guess at correlation? :confused:

Thank you for your answer, I’ll try that. Could I have a bit of an explanation about the fact that await Delay(0) would marshal back to the main thread ?

Thanks !

Maybe add an event handler for playerspawned?

It was solved by the 0 delay. I don’t remember what else was involved that caused it to crash, but the delay solved the issue presented here. There was something else going on, which caused me to improperly correlate it to the loading times, but I just don’t remember what. I never got around to replying back then.

2 Likes

Thanks for posting this…I just ran into the same issue recently and stumbled upon this thread, heh.

I’ll report back, but I presume that the Delay(0) will take care of it. Thanks! :smiley:

1 Like