Skip to content

subsequent calls to AddUrlSegment do not change value #2300

Description

@gregveres

I have a situation where part of my code sets a URL Segment to a value, and then calls the a function that executes the request with a retry if the auth fails.

Part of refreshing the auth retrieves the correct value of the URL Segment. So, I need to call AddUrlSegment again with the new, proper value and then execute the request again, now with the proper value.

But that doesn't work. RestSharp always uses the original value of the URL Segment. Here is a code snippet that illustrates the undesirable behaviour:

 RestClient client = new RestClient();
var request = new RestRequest("https://api.example.com/orgs/{segment}/something");
request.AddUrlSegment("segment", 1);
var url1 = client.BuildUri(request);
request.AddUrlSegment("segment", 2);
var url2 = client.BuildUri(request);

Expected out come:
url1 = {https://api.example.com/orgs/1/something}
url2 = {https://api.example.com/orgs/2/something}

actual out come:
url1 = {https://api.example.com/orgs/1/something}
url2 = {https://api.example.com/orgs/1/something}

  • OS: Windows 11 25H2 26200.6899
  • .NET version: 4.8.2
  • Version 112.1.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions