I am kinda confused on how I am getting this issue because I am not passing the IPlayer class into the serializer. Any help would be appreciated
Code:09:59 [Error] Failed to call hook 'cmdBan' on plugin 'BanManager v1.0.0' (JsonSerializationException: Self referencing loop detected for property 'gameObject' with type 'UnityEngine.GameObject'. Path 'player.Object.skeletonProperties.boneReference'.) 09:59 [Stacktrace] at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContainerContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.Serialization.JsonContract& memberContract, System.Object& memberValue) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <filename unknown>:0
Help with a Suspicious Error (JsonSerialzationException)
Discussion in 'Rust Development' started by Austinv900, Mar 20, 2017.
-
Maybe post the code lines of your saving method?
-
You can define an ignore for that: ReferenceLoopHandling setting
-
The BanEntry
Code:public class BanRecord { /// <summary> /// SteamID of the Player /// </summary> public string SteamId; /// <summary> /// PlayerName of the Player /// </summary> public string PlayerName; /// <summary> /// IP Address of the Player /// </summary> public string Address; /// <summary> /// The Reason for the Ban /// </summary> public string BanReason; /// <summary> /// The Server of the Ban /// </summary> public string BanServer = GetLibrary<Covalence>().Server.Address + ":" + GetLibrary<Covalence>().Server.Port.ToString(); /// <summary> /// Banned By User /// </summary> public string BannedBy; /// <summary> /// Length of Ban /// </summary> public int BanLength = 0; /// <summary> /// Ban Type /// </summary> public string BanType = "Empty"; /// <summary> /// Time Record was recorded /// </summary> public long TimeStamp = GetTimestamp(); public BanRecord(IPlayer player, string By, string Reason, int Time) { SteamId = player.Id; PlayerName = player.Name; try { Address = player.Address; } catch { } BanReason = Reason; BannedBy = By; BanLength = Time; } public BanRecord(string ID, string Name, string Address, string By, string Reason, int Time) { SteamId = ID; PlayerName = Name; this.Address = Address; BannedBy = By; BanReason = Reason; BanLength = Time; } public BanRecord() { } internal IPlayer GetIPlayerFromBan() { return Interface.Oxide.GetLibrary<Covalence>().Players.FindPlayer(SteamId); } internal string[] GetValueCSV() { return new string[] { SteamId, PlayerName, Address, BanReason, BanServer, BannedBy, BanLength.ToString(), FromEpoch(TimeStamp).ToShortDateString() }; }
Code:private bool InsertItem(BanRecord record) { if (lib == null) { LogError("Library is not loaded"); return false; } return (bool)eInsertItem.Invoke(lib, new object[] { JsonConvert.SerializeObject(record, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }) }); }
Code:[LibraryFunction("UpdateItem")] public bool UpdateItem(string Item) { DateTime start = DateTime.Now; BanRecord record = JsonConvert.DeserializeObject<BanRecord>(Item); MySqlCommand command = Connection.CreateCommand(); command.CommandText = $"UPDATE UserBans SET SteamId=\"{record.SteamId}\", PlayerName=\"{record.PlayerName}\", Address=\"{record.Address}\", BanReason=\"{record.BanReason}\", BanServer=\"{record.BanServer}\", BannedBy=\"{record.BannedBy}\", BanLength=\"{record.BanLength}\", TimeStamp=\"{record.TimeStamp}\" WHERE SteamId=\"{record.SteamId}\""; if (Connection.State == System.Data.ConnectionState.Closed) Connection.Open(); if (command.ExecuteNonQuery() > -1) { if (Connection.State == System.Data.ConnectionState.Open) Connection.Close(); if (Logger != null) Logger.Invoke(new LogEvent($"Database Function (Update) Took {(DateTime.Now - start).TotalMilliseconds}ms", "Extension->DatabaseManager", LogType.Info)); return true; } else { if (Connection.State == System.Data.ConnectionState.Open) Connection.Close(); if (Logger != null) Logger.Invoke(new LogEvent($"Database Function (Update) Took {(DateTime.Now - start).TotalMilliseconds}ms", "Extension->DatabaseManager", LogType.Info)); return false; } }