Newtonsoft.Json Deserialization Error in Tebex v2.0.5
I'm currently experiencing an issue with the Tebex v2.0.5 plugin for a game server, specifically related to a JSON deserialization error using the Newtonsoft.Json library. I'm hoping to find some assistance or suggestions on how to resolve this.
Error Description:
I'm encountering an exception during a web request callback in the Tebex plugin. The error message is as follows:
"Web request callback raised an exception in 'Tebex v2.0.5' plugin (Error converting value {null} to type 'System.Int64'. Path 'commands[0].package', line 1, position 391.)"
This suggests an issue with converting a null value to a `System.Int64` type during JSON deserialization.
Attempted Solutions:
- I've checked for any obvious mismatches in the JSON structure and the corresponding C# class properties.
- Ensured all long type properties are correctly mapped and formatted.
Seeking Suggestions:
- Any insights on handling null values in JSON deserialization for non-nullable types like `long` in C#.
- Tips on configuring the JsonConvert settings to avoid such issues.
- Recommendations for error handling practices in similar scenarios.
I am attaching relevant snippets of the code for reference. Any help or guidance would be greatly appreciated as I'm a bit stuck on how to proceed with debugging and resolving this issue.

Hey there, we'd need to see your server logs to assist here. Enable debug mode so that we can see the JSON response received from Tebex, as it looks like the response is in some unexpected state, specifically with a package attached to one of your commands.

To enable debug mode run tebex.debug on, allow the issue to occur again, and share the relevant portion of your server log.

[Tebex] [DEBUG] Deleting executed commands...
[Tebex] [DEBUG] No commands to flush.
[Tebex] [DEBUG] Processing player join queue...
[Tebex] [DEBUG] No recent join events.
donpo[76561############] has spawned
[Tebex] [DEBUG] Processing command queue...
[Tebex] [DEBUG] -> GET https://plugin.tebex.io/queue |
[Tebex] [DEBUG] 200 | '{"meta":{"execute_offline":false,"next_check":60,"more":false},"players":[{"id":1249717,"name":"maciota","uuid":"76561############"}]}' <- GET https://plugin.tebex.io/queue
[Tebex] [DEBUG] No offline commands to execute.
[Tebex] [DEBUG] Found 1 due players in the queue
[Tebex] [DEBUG] Processing online commands for player maciota...
[Tebex] [DEBUG] -> GET https://plugin.tebex.io/queue/online-commands/1249717 |
[Tebex] [DEBUG] 200 | '{"player":{"id":"76561############","username":"maciota","meta":{"avatar":"https:\/\/avatars.steamstatic.com\/b897660138de00609fd3cadf7b04f546e384b5db.jpg","avatarfull":"https:\/\/avatars.steamstatic.com\/b897660138de00609fd3cadf7b04f546e384b5db_full.[...]' <- GET https://plugin.tebex.io/queue/online-commands/1249717
[Tebex] [DEBUG] {"player":{"id":"76561############","username":"maciota","meta":{"avatar":"https:\/\/avatars.steamstatic.com\/b897660138de00609fd3cadf7b04f546e384b5db.jpg","avatarfull":"https:\/\/avatars.steamstatic.com\/b897660138de00609fd3cadf7b04f546e384b5db_full.jpg","steamID":"STEAM_0:0:120499931"}},"commands":[{"id":555038616,"command":"c.usergroup remove {id} vip","payment":69246008,"package":null,"conditions":{"delay":0,"slots":0}}]}
Web request callback raised an exception in 'Tebex v2.0.5' plugin (Error converting value {null} to type 'System.Int64'. Path 'commands[0].package', line 1, position 391.)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, object value, CultureInfo culture, JsonContract contract, Type targetType)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
at bool Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, object target)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, string id)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, object existingValue, string id)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
at bool Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, object target)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, string id)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, bool checkAdditionalContent)
at object Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at object Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at object Newtonsoft.Json.JsonConvert.DeserializeObject(string value, Type type, JsonSerializerSettings settings)
at OnlineCommandsResponse Newtonsoft.Json.JsonConvert.DeserializeObject<OnlineCommandsResponse>(string value, JsonSerializerSettings settings) x 2
at void Oxide.Plugins.BaseTebexAdapter.ProcessCommandQueue(bool ignoreWaitCheck)+(int onlineCommandsCode, string onlineCommandsResponseBody) => { } in /home/container/carbon/plugins/Tebex.cs:line 1233
at void Oxide.Plugins.TebexOxideAdapter.MakeWebRequest(string endpoint, string body, HttpVerb verb, ApiSuccessCallback onSuccess, ApiErrorCallback onApiError, ServerErrorCallback onServerError)+(int code, string response) => { } [0] in /home/container/carbon/plugins/Tebex.cs:line 1609
at void Oxide.Core.Libraries.WebRequests+WebRequest.OnComplete(bool failure)
Inner exception:
System.InvalidCastException: Null object cannot be converted to a value type.
at object Convert.ChangeType(object value, Type conversionType, IFormatProvider provider)
at object Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, object value, CultureInfo culture, JsonContract contract, Type targetType)

Thank you! It looks like for some reason there's not a package associated with a command or purchase, which is odd:

[Tebex] [DEBUG] {"player":{"id":"76561############",[steam user info],"commands":[{"id":555038616,"command":"c.usergroup remove {id} vip","payment":69246008,"package":null,"conditions":{"delay":0,"slots":0}}]}
We'll check into this ASAP and either provide a plugin update or an update post here on how to resolve this issue.