C# client-side resource fails to load libraries

I’ve been trying to use libraries on the client side for a while, without any success.
I always receive one of these errors:

  • System.DllNotFoundException
  • System.IO.FileNotFoundException
  • System.TypeLoadException

I tried almost every solution i could find on the internet, but at this point I think I’m missing something basic.
In particular, I suppose there must be an error with the transfer of the actual DLLs files to the clients, even if in my fxmanifest.lua I included:

file ‘Client/*.dll’

By the way I’m not sure about this, because while the resource is loading it still appears the Debug line:

Loaded [name of the library], Version=…, Culture=neutral, PublicKeyToken=… into ScriptDomain

The library I need to use right now is WebSocketSharp, which has no dependencies (it comes into a single dll file, no transitive packages).

If you want more material to examine PLEASE ask and I’ll be happy to show you.
Thanks in advance.

Sandboxing prevents some libraries from loading I believe, but I wouldn’t have thought a WebSocket library would be an issue.

Is sandboxing relevant? I don’t think it is in this case, and even if it was, as you said, it’s really strange that even a “simple” library without dependencies cannot load. By the way, thanks for the response. Have you got something to try to solve the problem?

Did you try including them as client scripts instead of files?

Yes I have, but no results. It just tries to run the libraries without success.

Even if the library has no dependencies it will still depend on runtime libraries such as System.Net, which obviously will fail to load on the client. Anyways a full error would be useful not just the exception class.

Sure thing:

[     26360] [    GTAProcess]             MainThrd/ Loaded haryel.Client.net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null into ScriptDomain_1708032259
[     26360] [    GTAProcess]             MainThrd/ Loaded websocket-sharp, Version=1.0.2.59611, Culture=neutral, PublicKeyToken=5660b08a1845a91e into ScriptDomain_1708032259
[     26360] [    GTAProcess]             MainThrd/ Failed to instantiate instance of script haryel.Client.ClientMain: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: Error verifying haryel.Client.ClientMain:.ctor (): Could not load type WebSocketSharp.WebSocket at 0x0000
[     26375] [    GTAProcess]             MainThrd/   at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
[     26375] [    GTAProcess]             MainThrd/   at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     26375] [    GTAProcess]             MainThrd/    --- End of inner exception stack trace ---
[     26375] [    GTAProcess]             MainThrd/   at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00014] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     26375] [    GTAProcess]             MainThrd/   at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x000a8] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     26375] [    GTAProcess]             MainThrd/   at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     26375] [    GTAProcess]             MainThrd/   at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00027] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     26375] [    GTAProcess]             MainThrd/   at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00020] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     26375] [    GTAProcess]             MainThrd/   at System.Activator.CreateInstance (System.Type type) [0x00000] in <b575c7ac070e41ffa0751333b6ac9f42>:0 
[     26375] [    GTAProcess]             MainThrd/   at CitizenFX.Core.InternalManager.CreateAssemblyInternal (System.String assemblyFile, System.Byte[] assemblyData, System.Byte[] symbolData) [0x000c4] in C:\gl\builds\master\fivem\code\client\clrcore\InternalManager.cs:156 

The files I have in the Client folder are these:

CitizenFX.Core.Client.dll
haryel.Client.net.dll
websocket-sharp.dll

(The resource is named haryel)

The sandbox is refusing to load WebSocketSharp.WebSocket. Again you cannot use these libraries on the client.

Is there anything I could do in your opinion? Thanks in advance.