Error on loading C# resource

Hello!

I was busy trying to learn to create my first C# FiveM script. After having added just a little code using the CitizenFX.Core.Client and CitizenFX.Core.Server dependencies, I figured I would try to upload it to the server and test it. But when starting the resource I got the following error message(s):

Registering Tick failed: System.TypeLoadException: Could not resolve type with token 01000018
  at (wrapper managed-to-native) System.Reflection.MonoMethodInfo:get_method_info (intptr,System.Reflection.MonoMethodInfo&)
  at System.Reflection.MonoMethodInfo.GetMethodInfo (System.IntPtr handle) [0x00000] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.Reflection.MonoMethod.GetPseudoCustomAttributes () [0x00002] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.MonoCustomAttrs.GetPseudoCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType) [0x0000a] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.MonoCustomAttrs.GetCustomAttributesBase (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inheritedOnly) [0x0001f] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.MonoCustomAttrs.GetCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inherit) [0x00037] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.Reflection.MonoMethod.GetCustomAttributes (System.Type attributeType, System.Boolean inherit) [0x00000] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at CitizenFX.Core.BaseScript+<>c__DisplayClass53_1.<InitializeOnAdd>b__1 (System.Reflection.MethodInfo m) [0x00000] in C:\gl\builds\master\fivem\code\client\clrcore\BaseScript.cs:382 
  at System.Linq.Enumerable+WhereArrayIterator`1[TSource].MoveNext () [0x0002c] in <31b946cfddcc4ab993dd6d559e89c25f>:0 
  at CitizenFX.Core.BaseScript.InitializeOnAdd () [0x000ae] in C:\gl\builds\master\fivem\code\client\clrcore\BaseScript.cs:388 
Registering EventHandler failed: System.TypeLoadException: Could not resolve type with token 01000018
  at (wrapper managed-to-native) System.Reflection.MonoMethodInfo:get_method_info (intptr,System.Reflection.MonoMethodInfo&)
  at System.Reflection.MonoMethodInfo.GetMethodInfo (System.IntPtr handle) [0x00000] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.Reflection.MonoMethod.GetPseudoCustomAttributes () [0x00002] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.MonoCustomAttrs.GetPseudoCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType) [0x0000a] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.MonoCustomAttrs.GetCustomAttributesBase (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inheritedOnly) [0x0001f] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.MonoCustomAttrs.GetCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inherit) [0x00037] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.Reflection.MonoMethod.GetCustomAttributes (System.Type attributeType, System.Boolean inherit) [0x00000] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at CitizenFX.Core.BaseScript+<>c__DisplayClass53_1.<InitializeOnAdd>b__1 (System.Reflection.MethodInfo m) [0x00000] in C:\gl\builds\master\fivem\code\client\clrcore\BaseScript.cs:382 
  at System.Linq.Enumerable+WhereArrayIterator`1[TSource].MoveNext () [0x0002c] in <31b946cfddcc4ab993dd6d559e89c25f>:0 
  at CitizenFX.Core.BaseScript.InitializeOnAdd () [0x001f9] in C:\gl\builds\master\fivem\code\client\clrcore\BaseScript.cs:408 
Registering command failed: System.TypeLoadException: Could not resolve type with token 01000018
  at (wrapper managed-to-native) System.Reflection.MonoMethodInfo:get_method_info (intptr,System.Reflection.MonoMethodInfo&)
  at System.Reflection.MonoMethodInfo.GetMethodInfo (System.IntPtr handle) [0x00000] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.Reflection.MonoMethod.GetPseudoCustomAttributes () [0x00002] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.MonoCustomAttrs.GetPseudoCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType) [0x0000a] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.MonoCustomAttrs.GetCustomAttributesBase (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inheritedOnly) [0x0001f] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.MonoCustomAttrs.GetCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inherit) [0x00037] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.Reflection.MonoMethod.GetCustomAttributes (System.Type attributeType, System.Boolean inherit) [0x00000] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at CitizenFX.Core.BaseScript+<>c__DisplayClass53_1.<InitializeOnAdd>b__1 (System.Reflection.MethodInfo m) [0x00000] in C:\gl\builds\master\fivem\code\client\clrcore\BaseScript.cs:382 
  at System.Linq.Enumerable+WhereArrayIterator`1[TSource].MoveNext () [0x0002c] in <31b946cfddcc4ab993dd6d559e89c25f>:0 
  at CitizenFX.Core.BaseScript.InitializeOnAdd () [0x00441] in C:\gl\builds\master\fivem\code\client\clrcore\BaseScript.cs:432 
Still executing script initialization routines...
Error invoking callback for event onClientResourceStart: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.BadImageFormatException: Error verifying Client.Client:<.ctor>b__0_0 (string): Cannot load method from token 0x0a00002c for newobj at 0x0039
  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 <74fbbe963b7e417b8d715b858c5c584f>: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 <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <74fbbe963b7e417b8d715b858c5c584f>:0 
  at CitizenFX.Core.EventHandlerEntry+<Invoke>d__5.MoveNext () [0x00064] in C:\gl\builds\master\fivem\code\client\clrcore\EventHandlerDictionary.cs:107

I looked on the internet, like stackoverflow and such, and found other people getting similar error messages because they were using outdated dependencies on the server side.

So I figured I would first try to update the server, but still no luck.

This is what I have tried so far

  • Updating the FXServer to the latest version (5350).
  • Make sure the FiveM Client is up to date (Beta branche).
  • Copy both server and client dependency and use those as references in VS22 (didn’t fix).
  • Use Nuget references to server and client dependencies (version 5350 for both, didn’t fix).
  • Copy the citizenfx.core.client/.server dependencies from the output directory and placed those in the according folders in the server and client (after renaming them to citizenfx.core).

This is what my solution in visual studio looks like:

image

I would appreciate any help or examples from other people on how they made a Client/Server script in C#!