Skip to content

JsonException for v2.items.manyAsync() probably because of schema version issues #143

@Taschenbuch

Description

@Taschenbuch

Problem:
when using await gw2ApiManager.Gw2ApiClient.V2.Items.ManyAsync(itemsWithoutDetails.Select(c => c.ApiId)); // ApiId is an int in Blish sometimes gw2sharp fails to deserialize the gw2 api response. once this has happened, any further attempt to call this endpoint will result in the same exception.
It seems to be caused by using different gw2api schema versions.

If you specify that in the browser you will see that secondary_suffix_item_id is now a number: https://api.guildwars2.com/v2/items/70068?v=latest
If you do that without specifying latest it takes whatever schema before 2020-11-17T00:30:00.000Z: https://api.guildwars2.com/v2/items/70068

relevant blish hud discord discussion:
https://discord.com/channels/531175899588984842/599270434642460753/1237043452999368855
a bit later in the discussion:
https://discord.com/channels/531175899588984842/599270434642460753/1237755071161176166

start of (long) relevant discussion in gw2sharp channel in gw2 development discord:
https://discord.com/channels/384735285197537290/589031897963692034/1294737623331635230

related github issue:
gw2-api/issues#106

example exception stack trace from blish hud farming tracker module:

21:44:09.1489 | WARN  | FarmingTracker.Module | API error: get stat details from v2.items failed
FarmingTracker.Gw2ApiException: API error: get stat details from v2.items failed ---> System.Text.Json.JsonException: The JSON value could not be converted to System.Nullable`1[System.Int32]. Path: $.details.secondary_suffix_item_id | LineNumber: 0 | BytePositionInLine: 931. Path: $[18] | LineNumber: 0 | BytePositionInLine: 10883. ---> System.InvalidOperationException: Cannot get the value of a token type 'String' as a number.
   at System.Text.Json.Utf8JsonReader.TryGetInt32(Int32& value)
   at System.Text.Json.Utf8JsonReader.GetInt32()
   at System.Text.Json.Serialization.Converters.NullableConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[TValue](Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, Type returnType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options)
   at Gw2Sharp.Json.Converters.CastableTypeConverter.CastableTypeConverterInner`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.Converters.IEnumerableDefaultConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[TValue](Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, Type returnType, JsonSerializerOptions options)
   at Gw2Sharp.WebApi.Http.WebApiRequest.<ExecuteAsync>d__10`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Gw2Sharp.WebApi.V2.Clients.BaseEndpointBulkClient`2.<ManyAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at FarmingTracker.ItemDetailsSetter.<SetItemDetailsFromApi>d__0.MoveNext() in C:\Dev\blish\BlishHud-FarmingTracker\FarmingTracker\Details\ItemDetailsSetter.cs:line 33
   --- End of inner exception stack trace ---
   at FarmingTracker.ItemDetailsSetter.<SetItemDetailsFromApi>d__0.MoveNext() in C:\Dev\blish\BlishHud-FarmingTracker\FarmingTracker\Details\ItemDetailsSetter.cs:line 43
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at FarmingTracker.StatsSetter.<SetDetailsAndProfitFromApi>d__0.MoveNext() in C:\Dev\blish\BlishHud-FarmingTracker\FarmingTracker\Details\StatsSetter.cs:line 19
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at FarmingTracker.SummaryTabView.<UpdateStatsInModel>d__11.MoveNext() in C:\Dev\blish\BlishHud-FarmingTracker\FarmingTracker\SessionSummary\SummaryTabView.cs:line 288
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at FarmingTracker.SummaryTabView.<UpdateStats>d__7.MoveNext() in C:\Dev\blish\BlishHud-FarmingTracker\FarmingTracker\SessionSummary\SummaryTabView.cs:line 200

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions