RestSharp returns: ‘Value cannot be null. /n Parameter name: src’ – http status 0

  android, c#, xamarin, xamarin.forms

I’ve made a Xamarin app, that has been working for a while.
After updating the Android SDK to version 9, I’m getting the wierdest error, when using RestSharp to make requests.

Here’s the skinny:

  • Anything that should return http status 200, works as it should: I get a 200 response. All fine and dandy.
  • Anything that should return any error (400, 404, 422, etc.), returns http status 0 (?!).

This happens regardless of if I ping the project API or any other APIs I try to ping (I’ve tried 3).

I’ve enabled access logs on the API and I can see that the server responds with a 422:

restsharp http code status 0 when it should be 422

But in my code I see the baffling http status 0, with the error:

Value cannot be null. /n Parameter name: src

Here is how it looks:

restsharp http code 0 in visual code

I’ve played around with it for hours (no exaggeration), – and I’m REALLY intelligent, so it’s no small dumb error, like a missing semi-colon or something. 😉

I’ve tried using client.execute( request ); as well, but with the same response.

RestSharp version: 106.11.4
Xamarin Forms version:
Visual Studio (2017) version: 15.9.26
Mono version: 8.1

Stack trace

at System.Net.HttpWebRequest+<RunWithTimeoutWorker>d__241`1[T].MoveNext () [0x000e8] in /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/mcs/class/System/System.Net/HttpWebRequest.cs:956
--- End of stack trace from previous location where exception was thrown ---
  at System.Net.WebConnectionStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x00070] in /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/mcs/class/System/System.Net/WebConnectionStream.cs:136
  at RestSharp.Extensions.MiscExtensions.ReadAsBytes (System.IO.Stream input) [0x0001c] in <bcf8430f35f545739e5ed4fc6c9a130d>:0
  at RestSharp.Http+<>c__DisplayClass166_0.<ExtractResponseData>g__ProcessResponseStream|1 () [0x00037] in <bcf8430f35f545739e5ed4fc6c9a130d>:0
  at RestSharp.Http.ExtractResponseData (System.Net.HttpWebResponse webResponse) [0x001fd] in <bcf8430f35f545739e5ed4fc6c9a130d>:0
  at RestSharp.Http.ExecuteRequest (System.String httpMethod, System.Action`1[T] prepareRequest) [0x0001c] in <bcf8430f35f545739e5ed4fc6c9a130d>:0

Source: Android Questions

One Reply to “RestSharp returns: ‘Value cannot be null. /n Parameter name: src’ – http status 0”