Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Adding a parameter twice to the url template triggers exception #1052

Closed
hansmbakker opened this issue Feb 3, 2021 · 2 comments · Fixed by #1055
Closed

[BUG] Adding a parameter twice to the url template triggers exception #1052

hansmbakker opened this issue Feb 3, 2021 · 2 comments · Fixed by #1055
Assignees
Labels

Comments

@hansmbakker
Copy link
Contributor

Describe the bug
Repeating the same parameter name multiple times in the url template causes Refit to crash at runtime

Steps To Reproduce
The repeated zoneId parameter in the code below causes the generated Refit code to crash at runtime. The exception is:
System.ArgumentException: An item with the same key has already been added.

[Get("/goform/formZone{zoneId}_Zone{zoneId}XmlStatusLite.xml")]
Task<Schema.ZoneStatus.ZoneStatus> IDenonHttpClient.GetDenonSecondaryZonesStatusAsync(int zoneId, CancellationToken cancellationToken)

Expected behavior
The code does not crash.

Screenshots

Unhandled exception. System.ArgumentException: An item with the same key has already been added. Key: 0
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at Refit.RestMethodInfo.BuildParameterMap(String relativePath, List`1 parameterInfo) in /_/Refit/RestMethodInfo.cs:line 178
   at Refit.RestMethodInfo..ctor(Type targetInterface, MethodInfo methodInfo, RefitSettings refitSettings) in /_/Refit/RestMethodInfo.cs:line 68
   at Refit.RequestBuilderImplementation.AddInterfaceHttpMethods(Type interfaceType, Dictionary`2 methods) in /_/Refit/RequestBuilderImplementation.cs:line 76
   at Refit.RequestBuilderImplementation..ctor(Type refitInterfaceType, RefitSettings refitSettings) in /_/Refit/RequestBuilderImplementation.cs:line 52
   at Refit.RequestBuilderImplementation`1..ctor(RefitSettings refitSettings) in /_/Refit/RequestBuilderImplementation.cs:line 19
   at Refit.RequestBuilderFactory.Create[T](RefitSettings settings) in /_/Refit/RequestBuilderFactory.cs:line 15
   at Refit.RequestBuilder.ForType[T](RefitSettings settings) in /_/Refit/RequestBuilder.cs:line 21
   at Refit.RestService.For[T](HttpClient client, RefitSettings settings) in /_/Refit/RestService.cs:line 18
   at Refit.RestService.For[T](String hostUrl, RefitSettings settings) in /_/Refit/RestService.cs:line 27

Environment

  • Version: Refit 5.2.4

Additional context
A workaround is to add another parameter with a different name having the same value.

@hansmbakker
Copy link
Contributor Author

That's fast! Thank you!👍🏻

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants