C# Exports Issue

I have exports functioning – sort of. After I execute the following code 4 times (exactly 4 times, always), I get the error after the code here.

TriggerEvent("chatMessage", $"string is: {Exports["ExportTest"].GetMyString()}", new int[] { 255, 255, 100 });
Exports["ExportTest"].SetMyString();
TriggerEvent("chatMessage", $"NEW string is: {Exports["ExportTest"].GetMyString()}", new int[] { 255, 255, 100 });

The error:

[    702972] System.InvalidOperationException: Tried to decode invalid MsgPack type 216

[    702972]   at CitizenFX.Core.MsgPackDeserializer.GetUnpacker (System.Byte type) [0x00232] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:387 

[    702987]   at CitizenFX.Core.MsgPackDeserializer.UnpackAny (System.IO.BinaryReader reader) [0x00007] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:30 

[    702987]   at CitizenFX.Core.MsgPackDeserializer.UnpackArray (System.IO.BinaryReader reader, System.Int32 length) [0x0000a] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:56 

[    702987]   at CitizenFX.Core.MsgPackDeserializer.UnpackFixArray (System.Byte a, System.IO.BinaryReader reader) [0x00005] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:217 

[    702987]   at CitizenFX.Core.MsgPackDeserializer.UnpackAny (System.IO.BinaryReader reader) [0x0000f] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:32 

[    702987]   at CitizenFX.Core.MsgPackDeserializer.Deserialize (System.Byte[] data, System.String netSource) [0x0001b] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:24 

[    702987]   at CitizenFX.Core.InternalManager.TriggerEvent (System.String eventName, System.Byte[] argsSerialized, System.String sourceString) [0x00021] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\InternalManager.cs:194 
[    703003] System.InvalidOperationException: Tried to decode invalid MsgPack type 216

[    703018]   at CitizenFX.Core.MsgPackDeserializer.GetUnpacker (System.Byte type) [0x00232] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:387 

[    703018]   at CitizenFX.Core.MsgPackDeserializer.UnpackAny (System.IO.BinaryReader reader) [0x00007] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:30 

[    703018]   at CitizenFX.Core.MsgPackDeserializer.UnpackArray (System.IO.BinaryReader reader, System.Int32 length) [0x0000a] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:56 

[    703018]   at CitizenFX.Core.MsgPackDeserializer.UnpackFixArray (System.Byte a, System.IO.BinaryReader reader) [0x00005] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:217 

[    703018]   at CitizenFX.Core.MsgPackDeserializer.UnpackAny (System.IO.BinaryReader reader) [0x0000f] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:32 

[    703034]   at CitizenFX.Core.MsgPackDeserializer.Deserialize (System.Byte[] data, System.String netSource) [0x0001b] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:24 

[    703034]   at CitizenFX.Core.InternalManager.TriggerEvent (System.String eventName, System.Byte[] argsSerialized, System.String sourceString) [0x00021] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\InternalManager.cs:194 
[    703096] Failed to run a tick for BriglairRP: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: `CitizenFX.Core.ExportSet' does not contain a definition for `SetMyString'

[    703096]   at (wrapper dynamic-method) System.Object:CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object)

[    703112]   at BriglairRP.BriglairRP+<OnTick>d__29.MoveNext () [0x001e3] in <5b47632a963648579b8af455cf3355bd>:0 
[    703112] 

The primary thing I see from this is the following. If I were to run it again, it would then say `GetMyString’ isn’t there.

`CitizenFX.Core.ExportSet' does not contain a definition for `SetMyString'

The code for my exports resource is:

public class ExportTestCL : BaseScript
    {
        string thisString = "TEST(1)";
        public delegate string SimpleDelegate();
        public delegate void SimpleDelegate2();
        public ExportTestCL()
        {
            SimpleDelegate simpleDelegate = new SimpleDelegate(GetMyString);
            SimpleDelegate2 simpleDelegate2 = new SimpleDelegate2(SetMyString);

            Exports.Add("GetMyString", simpleDelegate);
            Exports.Add("SetMyString", simpleDelegate2);
        }

        public string GetMyString()
        {
            return thisString;
        }

        public void SetMyString()
        {
            thisString += " (+)";
        }
    }

Well it looks like the script name is ExportTestCL have you tried that instead of ExportTest to see if it fixes the issue

Ah, that issue actually happens with exports in certain cases? It’ll be added to the to-do list for the next FiveM development cycle.

Also see this:

Any other testing I could do on my end in order to help with debugging?


It needs the resource name, which is actually ExportTest. The ExportTestCL is just the class name. It does work properly the first 3 times.

As a temporary workaround until the next FiveM development cycle starts, you can ensure the combination of resource name and certain internal identifiers does not ever equate to 16 characters.

Equate to 16 characters as in the length of the actual identifier(s) itself? None of the identifiers I use are exactly 16 characters (alone or with any combination).

I’m not quite sure I fully understand what you mean.

Whenever I join the server, “nil ~= 1” is printed in the server console. This is only when my ExportTest resource is started. It prints out when I first spawn after connecting. I’m not sure if this is related at all or a bug.

Exports working properly since the update. Thanks, guys!