Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tim-ebu opened this issue Dec 14, 2022 · 0 comments
Open

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

tim-ebu opened this issue Dec 14, 2022 · 0 comments

Comments

@tim-ebu
Copy link

tim-ebu commented Dec 14, 2022

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant