[C#] Unknown error using 'chatMessage'

So I was trying to make a script using the whole new server side C# scripting that is so amazing, and I see myself as a decent C# developer. When I made my script, it was working fine when I was by myself in the server and even when it was me and my friend. The only problem is that it seems like if there are 3 or more people in the server invoking the command crashes the entire resource and I need to restart it and it still crashes. I honestly have no idea what is going on and I can’t even read the stack trace. Can someone help me with the topic please!

stack trace:

Error invoking callback for event chatMessage: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.Remoting.RemotingException: Server for uri '94f00adc_6926_464e_8368_4c8b38abf5a2/5767589_2.rem' not found


Server stack trace: 
  at System.Runtime.Remoting.Proxies.RealProxy.GetAppDomainTarget () [0x00031] in <d7e663f2f7cd4ab6929018ec5233f09d>:0 
  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:163 
  at CitizenFX.Core.ScriptContext.Invoke (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x00000] in /src/code/client/clrcore/ScriptContext.cs:156 
  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 RagdollCMD.Server.RagdollCMD.OnChatMessage (System.Int32 source, System.String n, System.String message) [0x00032] in <9f53b56ab4b64d528622fca586365056>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <d7e663f2f7cd4ab6929018ec5233f09d>:0 
   --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <d7e663f2f7cd4ab6929018ec5233f09d>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <d7e663f2f7cd4ab6929018ec5233f09d>:0 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <d7e663f2f7cd4ab6929018ec5233f09d>:0 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <d7e663f2f7cd4ab6929018ec5233f09d>:0 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <d7e663f2f7cd4ab6929018ec5233f09d>:0 
  at CitizenFX.Core.EventHandlerEntry+<Invoke>d__5.MoveNext () [0x00122] in /src/code/client/clrcore/EventHandlerDictionary.cs:144 
Command 'ragdoll' entered..

server side:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CitizenFX.Core;
using CitizenFX.Core.Native;

namespace RagdollCMD.Server
{
    public class RagdollCMD : BaseScript
    {
        public RagdollCMD()
        {
            Debug.WriteLine("Ragdoll script by BlockBa5her started");
            this.EventHandlers["chatMessage"] += new Action<int, string, string>(this.OnChatMessage);
        }

        public void OnChatMessage(int source, string n, string message)
        {
            string[] args = message.Split(' ');
            Player p = this.Players[source];
            if (args[0] == "/ragdoll")
            {
                TriggerClientEvent(p, "rcmd:Ragdoll");
            }
            else if (args[0] == "/cancelragdoll")
            {
                TriggerClientEvent(p, "rcmd:CancelRagdoll");
            }
        }
    }
}

client side:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CitizenFX.Core;

namespace RagdollCMD.Client
{
    public class RagdollCMD : BaseScript
    {
        bool isPedRagdoll = false;
        bool cancelRagdoll = true;
        Ped Char => this.LocalPlayer.Character;

        public RagdollCMD()
        {
            this.EventHandlers.Add("rcmd:Ragdoll", new Action(() =>
            {
                isPedRagdoll = !isPedRagdoll;
                if (isPedRagdoll)
                    TriggerEvent("chatMessage", "RagdollCMD", new[] { 0, 0, 0 }, "^2Now ragdolling");
                else
                {
                    TriggerEvent("rcmd:CancelRagdoll");
                    TriggerEvent("chatMessage", "RagdollCMD", new[] { 0, 0, 0 }, "^8No longer ragdolling");
                }
            }));
            this.EventHandlers.Add("rcmd:CancelRagdoll", new Action(() =>
            {
                if (isPedRagdoll)
                    cancelRagdoll = true;
            }));
            this.Tick += this.OnTick;
        }

        private async Task OnTick()
        {
            if (this.isPedRagdoll && this.Char.IsInVehicle())
                this.Char.Task.LeaveVehicle(LeaveVehicleFlags.LeaveDoorOpen);
            if (this.isPedRagdoll)
                if (this.Char.CanRagdoll)
                    this.Char.Ragdoll(1000, RagdollType.Normal);
            if (this.cancelRagdoll)
            {
                this.isPedRagdoll = false;
                this.cancelRagdoll = false;
                this.Char.CancelRagdoll();
            }
            await Delay(5);
        }
    }
}

@BlockBa5her Sorry for the bump, but did you ever find a fix for this problem?

I’m getting the same thing, and it only happens when the server is first started/restarted. If I restart the resource once or twice, it’s perfectly fine after that. :\

Honestly, I never found a fix. It only happened to me when it was first started. IDK what the issue is. Maybe someone here would have an idea @moderators

@BlockBa5her This needs to be tested some more. But I think I might have solved it.

I changed the code from:

Player p = Players[source];

to

PlayerList pl = new PlayerList();
Player p = pl[source];

After clearing the cache and restarting the server, the errors were gone, with two different scripts. I did another cache clear and restart, same thing.

Like I said, I don’t know if this really fixed it, and it could just be dumb luck, so it will have to be monitored. But this seems to have made an immediate impact.

EDIT: Nope…

@BlockBa5her That’s a negative…just got the error again. :frowning:

1 Like

Still having issues with this. It seems to happen on the Player.TriggerEvent call, even in a custom server event. Can anyone from the FiveM team take a look?

System.Runtime.Remoting.RemotingException: Server for uri '374dca40_09ca_4b7f_a886_a5f2de357ed5/df2c9b5c_5.rem' not found
Server stack trace:
at System.Runtime.Remoting.Proxies.RealProxy.GetAppDomainTarget () [0x00031] in <fb0d2884a2b44d8db375bbed7cc70740>:0
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:168
at CitizenFX.Core.ScriptContext.Invoke (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x00000] in /src/code/client/clrcore/ScriptContext.cs:161
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