2

I've sent a PUT request and got NullReferenceException in RestSharp.Portable:

using (var client = new RestClient(new Uri(BaseUri)))
{
    var oAuth1Authenticator = OAuth1Authenticator.ForAccessToken(
      OAuthConsumerKey,
      OAuthConsumerSecret,
      oAuthToken", 
      oAuthSecret"
    );

    client.Authenticator = oAuth1Authenticator;

    var request = new RestRequest(lastPartUri, httpMethod);

    request.AddJsonBody(body);

    IRestResponse response = await client.Execute(request);

    return response.Content;
}

Line IRestResponse response = await client.Execute(request); thrown the exception.

OAuth params are definitely not null, neither are BaseUri and lastPartUri. body is a Dictionary<string, string> and is not null too.

POST and GET requests with the same parameters work just fine.

Looks like the problem is in RestSharp library. How can I find it?

Here is the stack trace:

   at RestSharp.Portable.Authenticators.OAuth1Authenticator.<>c.<AddOAuthData>b__84_3(Parameter p)
   at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
   at RestSharp.Portable.Authenticators.OAuth1Authenticator.AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflow workflow)
   at RestSharp.Portable.Authenticators.OAuth1Authenticator.PreAuthenticate(IRestClient client, IRestRequest request, ICredentials credentials)
   at RestSharp.Portable.RestClientBase.<ExecuteRequest>d__67.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at RestSharp.Portable.HttpClient.RestClient.<Execute>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Store.Helpers.MyBookApiConnector.<SendRequest>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Store.Services.DataService.<UpdateReview>d__80.MoveNext()

Before exception After exception

madhead
  • 31,729
  • 16
  • 153
  • 201
Dmitry
  • 1,095
  • 14
  • 21
  • From the stacktrace, it looks like the null reference exception is occurring in the `OAuthAutheticator`. Do any of the values supplied to the Authenticator have the value `null`? – Lars Kristensen Aug 19 '16 at 10:39
  • I dont know much C#, but isn't OP missing a semicolon after the `var 01Auth...` block of code? – S.V. Aug 19 '16 at 10:50
  • @LarsKristensen values not null. I'm updated question. – Dmitry Aug 19 '16 at 11:00
  • @DrSatan1 yes, it is after edit for SO. – Dmitry Aug 19 '16 at 11:01
  • @Enigmativity reopen question! – Dmitry Aug 19 '16 at 11:33
  • @MakeMakeluv - Why do you think it is not a duplicate? – Enigmativity Aug 19 '16 at 11:58
  • 2
    I'm not ask about what is it NullReferenceException. I'm ask how find why ecxeption throw only on PUT method only on RestSharp. – Dmitry Aug 19 '16 at 12:00
  • 2
    Hey, @Enigmativity, this question looks to be valid, not a duplicate. It may be [a bug in `RestSharp`](https://github.com/FubarDevelopment/restsharp.portable/issues/84), but definitely it's not a "what is a NRE?" question. Can you please consider a possibility to reopen it? Even if it will not get an answer, it may help others to track that defect. – madhead Oct 15 '16 at 23:18

1 Answers1

2

This was indeed a bug in the library. The developer is already fixed.

Dmitry
  • 1,095
  • 14
  • 21