It works great when running the resource on windows, but as soon as I switch to Linux there are a lot of errors which i can’t figure out how to solve… I’ve tested to make sure that this is actually causing it, and commenting out the code to perform my request removes the errors on runtime…
This is what I was getting at first: https://hastebin.com/pijuroqoso
Then, after adding System.Numerics.dll to the references of my resource, making it copy the dll to the output folder and adding it to the server_scripts section in my __resource.lua gave me this error instead: https://hastebin.com/uxufodegub
The format of the System.Numerics.dll did not coincide with the runtime, e.g. 32bit vs 64bit. Probably an MSIL image for just windows systems might be better.
I figured it out. A dll file is missing in the linux server artifacts, when copying it from my windows server artifacts to the linux server artifacts it works fine.
@zr0iq@Vespura Sorry to bump this thread after a long time, but I have a question about this helper class.
How does making requests this way differ from using the built-in HttpClient class in .NET?
In the plugin I’m writing, I hadn’t seen this gist (and HttpClient is how I’m used to doing web requests in my .NET projects at work), so I started using the HttpClient class, and so far, it’s worked fine.
Is there some pitfall of FiveM that this method solves, or something?
I know this is old but I didn’t want to create my own topic. I’m trying to use this to communicate with php on my website but I’m getting this error
InvokeNative: execution failed: No current resource manager.
Unhandled task 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 <fbc4ec45371543bfba3678ebb82caf6d>:0
at (wrapper cominterop) CitizenFX.Core.IScriptHost.InvokeNative(intptr)
at (wrapper cominterop-invoke) CitizenFX.Core.IScriptHost.InvokeNative(intptr)
at CitizenFX.Core.MonoScriptRuntime+WrapScriptHost.InvokeNative (System.IntPtr context) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\MonoScriptRuntime.cs:361
at (wrapper remoting-invoke-with-check) CitizenFX.Core.MonoScriptRuntime+WrapScriptHost.InvokeNative(intptr)
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(intptr)
at CitizenFX.Core.ScriptContext.InvokeInternal (CitizenFX.Core.fxScriptContext* cxt, System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x00007] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\ScriptContext.cs:348
at CitizenFX.Core.ScriptContext.InvokeInternal (System.UInt64 nativeIdentifier, CitizenFX.Core.IScriptHost scriptHost) [0x00015] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\ScriptContext.cs:335
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:326
at CitizenFX.Core.Native.Function.InvokeInternal (CitizenFX.Core.Native.Hash nativeHash, System.Type returnType, CitizenFX.Core.Native.InputArgument[] args) [0x00024] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\Native.cs:28
at CitizenFX.Core.Native.Function.Call[T] (CitizenFX.Core.Native.Hash hash, CitizenFX.Core.Native.InputArgument[] arguments) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\Native.cs:11
at CitizenFX.Core.RemoteFunctionReference._InvokeNative (System.Byte[] argsSerialized) [0x00026] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\RemoteFunctionReference.cs:92
at CitizenFX.Core.RemoteFunctionReference.InvokeNative (System.Byte[] argsSerialized) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\RemoteFunctionReference.cs:72
at CitizenFX.Core.MsgPackDeserializer+<>c__DisplayClass36_0.<CreateRemoteFunctionReference>b__0 (System.Object[] args) [0x00007] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:267
at (wrapper dynamic-method) System.Object.CallSite.Target(System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object,object[],bool)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2] (System.Runtime.CompilerServices.CallSite site, T0 arg0, T1 arg1, T2 arg2) [0x0011e] in <cf8f429092f345a6bd742c3476e00e06>:0
at CitizenFX.Core.FunctionReference+<>c__DisplayClass11_1.<Invoke>b__1 (System.Threading.Tasks.Task t) [0x00000] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\FunctionReference.cs:78
at System.Threading.Tasks.ContinuationTaskFromResultTask`1[TAntecedentResult].InnerInvoke () [0x00024] in <fbc4ec45371543bfba3678ebb82caf6d>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in <fbc4ec45371543bfba3678ebb82caf6d>:0
here’s my code:
private void OnResourceStart(string name)
{
if (GetCurrentResourceName() != name) return;
RegisterCommand("test", new Action<int, List<object>, string>(async (source, args, raw) =>
{
string data = "test";
Request r = new Request();
RequestResponse result = await r.Http("url", "POST", data);
}), false);
}
Hi, since the Gist is now down, does anyone have the original source code for HttpHelper.cs? It would be very helpful. When I use the WebRequest.Create() method in my client resource, it gives me a System.MethodAcessException, so I’m curious how it was worked around in the Gist.