Archomeda/Gw2Sharp

GuidConverter needs a null check

Closed this issue · 0 comments

The Guid constructor doesn't allow nulls.

image

If a character is requested that doesn't represent a guild, an ArgumentNullException is thrown.

Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'g')le.exe
   at System.Guid..ctor(String g)
   at Gw2Sharp.Json.Converters.GuidConverter.ReadJson(JsonReader reader, Type objectType, Guid existingValue, Boolean hasExistingValue, JsonSerializer serializer)
   at Newtonsoft.Json.JsonConverter`1.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)

image

public override Guid ReadJson(JsonReader reader, Type objectType, Guid existingValue, bool hasExistingValue, JsonSerializer serializer) =>
new Guid(serializer.Deserialize<string>(reader));

REF: https://discordapp.com/channels/384735285197537290/589031897963692034/669720102970589187