Skip to content

GetTotal method in Workbooks API for C# throws an exception #13

Description

@tim-ebu

This method:

public int? getTotal() {
if (response != null) {
Dictionary<string, object> responseData = (Dictionary<string, object>) response["response"];
total = (int?)responseData["total"];
}
return total;
}

throws an exception because the cast is invalid.

Suggested fix:

public int? getTotal() {
if (response != null) {
Dictionary<string, object> responseData = (Dictionary<string, object>) response["response"];
var t = (JsonElement)responseData["total"];
if (t.ValueKind == JsonValueKind.Number) return t.GetInt32();
}
return null;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions