1

I have a WebAPI in .NET Core 2.1 e I have using the RestSharp to access the API. When I send a request (POST), I always receive the below message in the response:


{System.Net.WebException: Error getting response stream (ReadAsync): ReceiveFailure Value cannot be null.Parameter name: src ---> System.ArgumentNullException: Value cannot be null.Parameter name: src at System.Net.HttpWebRequest+d__2411[T].MoveNext () [0x000ba] in <b78695579ed9422b8bc80218eeda782c>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <43dbbdc147f2482093d8409abb04c233>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <43dbbdc147f2482093d8409abb04c233>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <43dbbdc147f2482093d8409abb04c233>:0 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <43dbbdc147f2482093d8409abb04c233>:0 at System.Net.WebResponseStream+d__48.MoveNext () [0x00253] in :0 --- End of inner exception stack trace --- at System.Net.WebConnectionStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x00077] in :0 at RestSharp.Extensions.MiscExtensions.ReadAsBytes (System.IO.Stream input) [0x0001f] in <4b0c1fc6e5a94482990701acc6dec8b3>:0 at RestSharp.Http.ProcessResponseStream (System.IO.Stream webResponseStream, RestSharp.HttpResponse response) [0x0000e] in <4b0c1fc6e5a94482990701acc6dec8b3>:0 at RestSharp.Http.ExtractResponseData (RestSharp.HttpResponse response, System.Net.HttpWebResponse webResponse) [0x0004c] in <4b0c1fc6e5a94482990701acc6dec8b3>:0 at RestSharp.Http+<>c__DisplayClass20_0.b__0 (System.Net.HttpWebResponse webResponse) [0x00001] in <4b0c1fc6e5a94482990701acc6dec8b3>:0 at RestSharp.Http.GetRawResponseAsync (System.IAsyncResult result, System.Action1[T] callback) [0x00050] in <4b0c1fc6e5a94482990701acc6dec8b3>:0 at RestSharp.Http.ResponseCallback (System.IAsyncResult result, System.Action1[T] callback) [0x0005a] in <4b0c1fc6e5a94482990701acc6dec8b3>:0 }


The previous version of my service (.NET Framework 4.7) was working, but my new version is not. I checked the URL and that is okay, and the service is working on Swagger and Postman, and I have the SSL certificate configured on the server, but in the App I continue receiving such message.

My service is hosted on Microsoft Azure.

Does anyone any idea to help me?

1 Answer 1

-1

Ok. I resolved.

I had the below code:

IRestRequest request = new RestRequest(method, Method.POST);

request.AddParameter("SampleKey", "SampleValue");

I don´t know why it was working with a .Net Framework WebApi, but is not working with a .Net Core WebApi.

I could resolve using the below code:

IRestRequest request = new RestRequest(method, Method.POST);

request.AddJsonBody(objBody);

With the new method, the RestSharp is responsible to serialize my object.

It's working right now.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, I have the same issue, but server used SSO identify 4, it is not support input json. Could you have any other solution?
Hi Tony. Some days ago I had a problem similar to yours when I updated my RestSharp version from 106.4.2 to 106.5.4. I did the downgrade of the version (to 106.4.2) and the calls returned to work again. What version are you using?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.