-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
CG.Web.MegaApiClient.MegaApiClient.Login > Unable to cast object of type 'System.Int64' to type 'Newtonsoft.Json.Linq.JArray' #235
Milestone
Comments
Something like this fix the return (report to comments): private TResponse RequestCore<TResponse>(RequestBase request, byte[] key)
where TResponse : class
{
var dataRequest = JsonConvert.SerializeObject(new object[] { request });
var uri = GenerateUrl(request.QueryArguments);
object jsonData = null;
var attempt = 0;
// Added line
var apiCode = ApiResultCode.Ok;
while (_options.ComputeApiRequestRetryWaitDelay(++attempt, out var retryDelay))
{
var dataResult = _webClient.PostRequestJson(uri, dataRequest);
if (string.IsNullOrEmpty(dataResult)
|| (jsonData = JsonConvert.DeserializeObject(dataResult)) == null
|| jsonData is long
|| jsonData is JArray array && array[0].Type == JTokenType.Integer)
{
// Remove var keyword
apiCode = jsonData == null
? ApiResultCode.RequestFailedRetry
: jsonData is long
? (ApiResultCode)Enum.ToObject(typeof(ApiResultCode), jsonData)
: (ApiResultCode)((JArray)jsonData)[0].Value<int>();
if (apiCode != ApiResultCode.Ok)
{
ApiRequestFailed?.Invoke(this, new ApiRequestFailedEventArgs(uri, attempt, retryDelay, apiCode, dataResult));
}
if (apiCode == ApiResultCode.RequestFailedRetry)
{
Wait(retryDelay);
continue;
}
if (apiCode != ApiResultCode.Ok)
{
throw new ApiException(apiCode);
}
}
break;
}
// Added block
if (apiCode != ApiResultCode.Ok)
{
throw new ApiException(apiCode);
}
var data = ((JArray)jsonData)[0].ToString();
return (typeof(TResponse) == typeof(string)) ? data as TResponse : JsonConvert.DeserializeObject<TResponse>(data, new GetNodesResponseConverter(key));
} |
@dhabierre Thanks for the issue report. Would you mind proposing a PR? |
Hi @gpailler, I can do it at the end of the next week (in holidays at present time). |
dhabierre
added a commit
to dhabierre/MegaApiClient
that referenced
this issue
Dec 29, 2023
…pe 'Newtonsoft.Json.Linq.JArray' error Github issue: gpailler#235
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description:
The error occurres while executing the MegaApiClient
LoginAsync
method (~1 year without any error):Locally on my dev computer, no issue, everything is OK.
But once the app is deployed on my VM provider:
MegaApiClient Version: 1.10.3
Thanks.
The text was updated successfully, but these errors were encountered: