Greetings,
I have an API call that works often, but sometimes I get back an error I logged and it is this:
JniPeerMembers : Android.Runtime.XAPeerMembers
StackTrace : at Java.Interop.JniEnvironment+InstanceMethods.CallIntMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <11eeb492016f4a8c999585f0490be620>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0003c] in <11eeb492016f4a8c999585f0490be620>:0
at Java.Net.HttpURLConnection.get_ResponseCode () [0x0000a] in <81c1d29afadd437db7a7f9c0ac3aa46f>:0
at Xamarin.Android.Net.AndroidClientHandler+<>c__DisplayClass46_0.<DoProcessRequest>b__2 () [0x00000] in <81c1d29afadd437db7a7f9c0ac3aa46f>:0
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <ca06dc8ec1b243b7afbe4f88994c9098>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in <ca06dc8ec1b243b7afbe4f88994c9098>:0
--- End of stack trace from previous location where exception was thrown ---
at Xamarin.Android.Net.AndroidClientHandler.DoProcessRequest (System.Net.Http.HttpRequestMessage request, Java.Net.URL javaUrl, Java.Net.HttpURLConnection httpConnection, System.Threading.CancellationToken cancellationToken, Xamarin.Android.Net.AndroidClientHandler+RequestRedirectionState redirectState) [0x00372] in <81c1d29afadd437db7a7f9c0ac3aa46f>:0
at Xamarin.Android.Net.AndroidClientHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x002d0] in <81c1d29afadd437db7a7f9c0ac3aa46f>:0
at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in <8c3c451ac2a8478d9b689eaba35be510>:0
at NccitDriver.Servizi.JoClass.ChiamataApi (System.String stringa, System.String v) [0x00122] in <2d9806abe2d34a8e8845a2e1101b559f>:0
--- End of managed Java.IO.IOException stack trace ---
java.io.IOException: Canceled
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:156)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:30)
I've tried to handle exceptions but can't find a solution.
try
{
HttpClient client = new HttpClient
{
MaxResponseContentBufferSize = 512000,
Timeout = TimeSpan.FromMilliseconds(3000)
};
HttpResponseMessage response = await client.GetAsync(stringa);
if (response.IsSuccessStatusCode)
{
string content = await response.Content.ReadAsStringAsync();
if (content.Contains("id"))
{
risultato = System.Text.Json.JsonSerializer.Deserialize<Prenotazioni>(content);
}
else
{
risultato = null;
}
}
}
catch (TaskCanceledException tcex)
{
// The request timed out
}
catch (System.OperationCanceledException Cancellata)
{
return null;
}
catch (Exception err)
{
Log.Debug("ERRORE", err.Message);
Log.Debug("ERRORE", err.StackTrace);
}
return risultato;