Can't store C# Collections via Meta Data. It works with int, string, bool, etc., but whenever I try to save a collection (e.g. List or Dictionary) I just can't retrieve the stored value. Alt.GetMetaData returns false.
Here is my server-side code:
public class Starting : AsyncResource
{
public Starting() : base(true)
{}
public override void OnStart()
{
AltAsync.Log("STARTED!");
}
public override void OnStop()
{
throw new NotImplementedException();
}
}
public sealed class Test : IScript
{
public Test()
{
AltAsync.Log("-------------------------------------------------");
var list = new List<string>()
{
"Foo",
"Bar",
};
Alt.SetMetaData("TestMetaList", list);
AltAsync.Log($"TestMetaList key is existing: {Alt.HasMetaData("TestMetaList")}");
var listObtained = Alt.GetMetaData<List<string>>("TestMetaList", out var metaList);
AltAsync.Log($"List obtained from meta: {listObtained}");
AltAsync.Log($"metaList: {metaList}");
AltAsync.Log("-------------------------------------------------");
var dic = new Dictionary<string, string>()
{
{ "Foo", "Bar" },
};
Alt.SetMetaData("TestMetaDic", dic);
AltAsync.Log($"TestMetaDic key is existing: {Alt.HasMetaData("TestMetaDic")}");
var dicObtained = Alt.GetMetaData<Dictionary<string, string>>("TestMetaDic", out var metaDic);
AltAsync.Log($"Dictionary obtained from meta: {dicObtained}");
AltAsync.Log($"metaDic: {metaDic}");
AltAsync.Log("-------------------------------------------------");
var number = 1337;
Alt.SetMetaData("TestMetaNumber", number);
AltAsync.Log($"TestMetaNumber key is existing: {Alt.HasMetaData("TestMetaNumber")}");
var numberObtained = Alt.GetMetaData<int>("TestMetaNumber", out var metaNumber);
AltAsync.Log($"Number obtained from meta: {numberObtained}");
AltAsync.Log($"metaNumber: {metaNumber}");
AltAsync.Log("-------------------------------------------------");
var text = "Any text here...";
Alt.SetMetaData("TestMetaString", text);
AltAsync.Log($"TestMetaString key is existing: {Alt.HasMetaData("TestMetaString")}");
var textObtained = Alt.GetMetaData<string>("TestMetaString", out var metaText);
AltAsync.Log($"Number obtained from meta: {textObtained}");
AltAsync.Log($"metaText: {metaText}");
AltAsync.Log("-------------------------------------------------");
}
}
And here is the output:
[14:28:53] -------------------------------------------------
[14:28:53] TestMetaList key is existing: True
[14:28:53] List obtained from meta: False
[14:28:53] metaList:
[14:28:53] -------------------------------------------------
[14:28:53] TestMetaDic key is existing: True
[14:28:53] Dictionary obtained from meta: False
[14:28:53] metaDic:
[14:28:53] -------------------------------------------------
[14:28:53] TestMetaNumber key is existing: True
[14:28:53] Number obtained from meta: True
[14:28:53] metaNumber: 1337
[14:28:53] -------------------------------------------------
[14:28:53] TestMetaString key is existing: True
[14:28:53] Number obtained from meta: True
[14:28:53] metaText: Any text here...
[14:28:53] -------------------------------------------------
As you can see, when I was trying to save a collection as Meta Data, I couldn't get the saved value, even though the key was there.
Just take my C# code from above and start the server.
Check the console for output.
Expected behaviour
Able to store collections as Meta Data.
Additional context
No response
Operating system
Windows
Version
AltV.Net 16.0.8 | alt:V Server 16.0.127 (release)
Crashdump ID
No response
Confirmation of issue's presence
[X] By submitting this ticket, I affirm that I have verified the presence of this issue on the latest developer version available at the time of writing this ticket.
Description of the problem
Can't store C# Collections via Meta Data. It works with int, string, bool, etc., but whenever I try to save a collection (e.g. List or Dictionary) I just can't retrieve the stored value. Alt.GetMetaData returns false.
Here is my server-side code:
And here is the output:
As you can see, when I was trying to save a collection as Meta Data, I couldn't get the saved value, even though the key was there.
I'm not sure if it's a bug or expected behaviour, but I couldn't find anything about it in docs (https://docs.altv.mp/articles/meta_data.html?q=Meta)
Reproduction steps
Expected behaviour
Able to store collections as Meta Data.
Additional context
No response
Operating system
Windows
Version
AltV.Net 16.0.8 | alt:V Server 16.0.127 (release)
Crashdump ID
No response
Confirmation of issue's presence