I have a class that I serialize & deserialize with json.
public class ItemTemplate
{
public string LuaPath;
public string Category = "Clutter";
public List<string> Slots = new List<string>();
public double Weight = 1.0;
public bool IsStackable = true;
public ItemTemplate(string cat, List<string> slots, double weight, bool isStack, string lua)
{
Category = cat;
Slots = new List<string>(slots);
Weight = weight;
IsStackable = isStack;
LuaPath = lua;
}
}
public class ItemTemplates
{
public Dictionary<string, ItemTemplate> Items = new Dictionary<string, ItemTemplate>();
}
In file it looks like this
{
"Items": {
"SmallStone": {
"LuaPath": "Items/SmallRock",
"Category": "Projectile",
"Slots": [
"RightHand",
"LeftHand"
],
"Weight": 0.1,
"IsStackable": true
}
}
}
I use this function to serialize this
public static (T, string) ReadFromJson<T>(string path)
{
try
{
JsonSerializer js = new JsonSerializer();
StreamReader sr = new StreamReader(path);
JsonReader jr = new JsonTextReader(sr);
T obj = js.Deserialize<T>(jr);
sr.Close();
jr.Close();
return (obj, "");
}
catch (Exception e)
{
return (default(T), e.Message);
}
}
After I renamed "Slots" to "ValidContainers" in both C# files and json file I get following error:
Value cannot be null.
Parameter name: collection
I have no idea what's going on. It works only when I leave old "Slots" name in json file.