ExecuteTaskAsync fails if RestClient is created with parameterless constructor

1,383 views
Skip to first unread message

Vadim Kovalyov

unread,
Nov 21, 2014, 3:39:09 PM11/21/14
to rest...@googlegroups.com
First of all thanks for the amazing lib that you've developed. I used RestSharp in several of my projects and it worked great. With this release I had a small issue though. According to your guidelines I'd like to discuss it here first before creating an issue on Github.

Before last release (105.0.0 I believe) I could simply use default parameterless constructor for RestClient (via DI) and provide absolute URLs dynamically per every RestRequest. But now RestClient fails if was created with parameterless constructor and w/o setting BaseUrl property before calling ExecuteTaskAsync(). It wasn't really obvious and expected. Would it be better to still allow instantiating RestClient w/o base url and provide full url in RestRequest? 

Thanks.

Vadim Kovalyov

unread,
Nov 21, 2014, 3:44:37 PM11/21/14
to rest...@googlegroups.com
Adding a code sample:

            IRestClient restClient = new RestClient();
            IRestRequest request = new RestRequest("myAbsoluteUrl", Method.GET);
            IRestResponse response = await restClient.ExecuteTaskAsync(request);


Throws:
System.ArgumentNullException: Value cannot be null.
Parameter name: uri
    at System.UriBuilder..ctor(Uri uri)
   at RestSharp.RestClient.BuildUri(IRestRequest request)
   at RestSharp.RestClient.ConfigureHttp(IRestRequest request, IHttp http)
   at RestSharp.RestClient.ExecuteAsync(IRestRequest request, Action`2 callback, String httpMethod, Func`4 getWebRequest)
   at RestSharp.RestClient.ExecuteAsync(IRestRequest request, Action`2 callback)
   at RestSharp.RestClient.ExecuteTaskAsync(IRestRequest request, CancellationToken token)

Michael Hallett

unread,
Nov 21, 2014, 5:24:08 PM11/21/14
to rest...@googlegroups.com
So when 105.0 was release there was a breaking change for people who used the BaseUrl property to set the value rather than using the constructor.  The BaseUrl was originally a string and has now been converted to a Uri.  If you want to use DI then you just need to update your code to create a Uri rather than use a string.  Make sense?
Reply all
Reply to author
Forward
0 new messages