Newtonsoft.Json.JsonSerializationException
TactiTac0z
Right trying to load a json file
it wrote it sycessfully but loading not that much I imagen its becuse my class strutor is a bit too complicated for the json serilzation?
and if so any tips to make it a bit less complicated?

heres the class' its trying to work with
public class PluginData//main class
    {
        public Dictionary<IPlayer, CostumPlayerData> CosdumPlayerDatas;
        public Dictionary<IPlayer, List<tacti.Mail>> mails;
        public List<tacti.Question> questions;
    }

    public class CostumPlayerData//plese ignorre my awfull spelling :P
    {
        public float Goodwill;

        public List<string> GoodwillHistory;

        public CostumPlayerData(float goodwill, List<string> goodwillHistory)
        {
            Goodwill = goodwill;
            GoodwillHistory = goodwillHistory;

        }

        public CostumPlayerData()
        {
            Goodwill = 3;
            GoodwillHistory = new List<string>();
        }
    }

    public class Question
    {
        public string quesiton;
        public IPlayer player;

        public Question(string quesiton, IPlayer player)
        {
            this.quesiton = quesiton;
            this.player = player;
        }
    }

    public class Mail
    {
        public string message;
        public IPlayer player;

        public Mail(string message, IPlayer player)
        {
            this.message = message;
            this.player = player;
        }
    }​

perhaps if I used long insted of Iplayer so just indexing useing the steam id would be better?
TactiTac0z
Original Poster
ohh and I forgot the exception message:

Newtonsoft.Json.JsonSerializationException: Could not convert string 'Covalence.RustPlayer[76561198166687451, Ta©ti Tac0Z]' to dictionary key type 'Oxide.Core.Libraries.Covalence.IPlayer'. Create a TypeConverter to convert from the string to the key type object. Path 'mails['Covalence.RustPlayer[76561198166687451, Ta©ti Tac0Z]']', line 4, position 59. ---> Newtonsoft.Json.JsonSerializationException: Error converting value "Covalence.RustPlayer[76561198166687451, Ta©ti Tac0Z]" to type 'Oxide.Core.Libraries.Covalence.IPlayer'. Path 'mails['Covalence.RustPlayer[76561198166687451, Ta©ti Tac0Z]']', line 4, position 59. ---> System.ArgumentException: Could not cast or convert from System.String to Oxide.Core.Libraries.Covalence.IPlayer.
and then about 3 A4 pages of stacktrace :P

and here is the product from the writeobject process it managed to do that its trying to unserialize:
{
"CosdumPlayerDatas": {},
"mails": {
"Covalence.RustPlayer[76561198166687451, Ta©ti Tac0Z]": [
{
"message": " Heya!",
"player": {
"Object": null,
"LastCommand": 1,
"Name": "Server Console",
"Id": "server_console",
"Language": "en-US",
"Address": "127.0.0.1",
"Ping": 0,
"IsAdmin": true,
"IsBanned": false,
"IsConnected": true,
"IsSleeping": false,
"IsServer": true,
"BanTimeRemaining": "00:00:00",
"Health": 0.0,
"MaxHealth": 0.0
}
}
]
},
"questions": []
}
if its of any use at all

Wulf
uMod Admin
You can’t store an entire player object, it won’t translate. Steam ID is generally all you need as a key.
TactiTac0z
Original Poster
Ha yeah I expected that to be the problem

Merged post

There is something wrong tho so I made a little quick test:
[Command("debug.testData")]
        private void TestDataCommand(IPlayer player, string command, string[] args)
        {
            Puts("writeing debuging object...");

            string testN = "TestData";

            Interface.Oxide.DataFileSystem.WriteObject<tacti.Mail>(testN, new tacti.Mail("Something", player));

            Puts("reading debuging object...");

            tacti.Mail mail = Interface.Oxide.DataFileSystem.ReadObject<tacti.Mail>(testN);

            Puts("done... " + mail.message + " " + mail.player);
        }

public class Mail
    {
        public string message;
        public string player; //note I chanced this field to a string insted of IPlayer

        public Mail(string message, IPlayer player)
        {
            this.message = message;
            this.player = player.Id;
        }
    }​

But even tho I've chanced it to a string it still says:

ExType: JsonSerializationException

(09:20:30) | Failed to call hook 'TestDataCommand' on plugin 'TactiPLugin v1.0.0' (ArgumentException: Could not cast or convert from System.String to Oxide.Core.Libraries.Covalence.IPlayer.)

at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable (System.Object value, System.Type initialType, System.Type targetType) [0x00062] in <8fe7f8665ff548909c2f26d557e5093a>:0

at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast (System.Object initialValue, System.Globalization.CultureInfo culture, System.Type targetType) [0x00031] in <8fe7f8665ff548909c2f26d557e5093a>:0

at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType (Newtonsoft.Json.JsonReader reader, System.Object value, System.Globalization.CultureInfo culture, Newtonsoft.Json.Serialization.JsonContract contract, System.Type targetType) [0x0008d] in <8fe7f8665ff548909c2f26d557e5093a>:0

where am I trying to cast string to Iplayer? no where right?

Wulf
uMod Admin
Your Mail class has the player set as a string, but you are trying to pass it as IPlayer; won't work.
TactiTac0z
Original Poster
No I'm not? where?

public class Mail
    {
        public string message;
        public string player; //yes this is a string

        public Mail(string message, IPlayer player //and yes this is an IPlayer)
        {
            this.message = message;
            this.player = player.Id; //but I'm sitting the field Id of Iplayer not Iplayer to mails field player :P
        }
    }​​
Wulf
uMod Admin
        public string player; //yes this is a string

        public Mail(string message, IPlayer player //and yes this is an IPlayer)

Can't make an IPlayer out of a string.

TactiTac0z
Original Poster
Does the unserilizer use the construtor to create classes?
2CHEVSKII
Plugin Developer
In response to TactiTac0z (View post):
Does the unserilizer use the construtor to create classes?
I think its better for you to simply test a class without constructor. Serializer does not create classes. It creates objects.
TactiTac0z
Original Poster
Yes but why the hell doesn't it work then? :P
public string player; //field is string

public Mail(string message, IPlayer player) //we are useing a IPlayer here

this.player = player.Id; //but we're useing the string id of the Iplayer (we are NOT trying to parse any string into a IPlayer anywere so what is the things problem?​

Dunno if wolf didn't notice the player.ID part?



Merged post

Also emm When the a rcon console runs a command a intance of IPlayer will be made with the id server_console but ofcause when trying to do players.findPlayerById and put server_console into that opcause it will say that server_console doesn't exists so have to create a new instance of IPlayer in the case of server_console being the id so BasePlayer is useing the IPlayer interface right?