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

System.ArgumentException: An item with the same key has already been added. Key: limit #567

Closed
smfields opened this issue Mar 1, 2021 · 8 comments

Comments

@smfields
Copy link

smfields commented Mar 1, 2021

Getting this error when trying to make a call to Client.Browse.GetCategoryPlaylists and passing a CategoriesPlaylistsRequest. The CategoriesPlaylistsRequest is

{
    Country = null,
    Limit = 1,
    Offset = null
}

Here's the full stack trace:

System.ArgumentException: An item with the same key has already been added. Key: limit
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at SpotifyAPI.Web.RequestParams.AddQueryParam(Dictionary`2 queryParams, PropertyInfo prop, QueryParamAttribute attribute) in D:\Documents\GitHub\SpotifyAPI-NET\SpotifyAPI.Web\Models\Request\RequestParams.cs:line 149
   at SpotifyAPI.Web.RequestParams.BuildQueryParams() in D:\Documents\GitHub\SpotifyAPI-NET\SpotifyAPI.Web\Models\Request\RequestParams.cs:line 76
   at SpotifyAPI.Web.BrowseClient.GetCategoryPlaylists(String categoryId, CategoriesPlaylistsRequest request) in D:\Documents\GitHub\SpotifyAPI-NET\SpotifyAPI.Web\Clients\BrowseClient.cs:line 51
   at MusicPlatform.Spotify.SpotifyPlatform.GetPlaylistsByGenre(Genre genre, PlaylistsGetRequest request) in C:\Users\54962\source\repos\smfields\Boogie\Boogie\MusicPlatform\Models\Implementations\Spotify\SpotifyPlatform.cs:line 141
   at MorseCode.ITask.TaskAwaiterWrapper`1.MorseCode.ITask.IAwaiter<TResult>.GetResult()
   at Groovy.Controllers.PlaylistController.GetPlaylistsByGenre(Platform platform, Genre genre, Nullable`1 limit, Nullable`1 offset) in C:\Users\54962\source\repos\smfields\Boogie\Boogie\Boogie\Controllers\PlaylistController.cs:line 129
   at lambda_method73(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
@smfields
Copy link
Author

smfields commented Mar 1, 2021

Note that I'm using a local build of the latest GitHub checkout because I need access to the NextPage and PreviousPage functionality recently added but not yet released.

@JohnnyCrazy
Copy link
Owner

@smfields Mh, this is a weird bug. Do you know if some call before this exception succeed? Or is the first call already failing?

@smfields
Copy link
Author

smfields commented Mar 2, 2021

@JohnnyCrazy As far as I can tell at least one call succeeded before this, if not more.

@JohnnyCrazy
Copy link
Owner

JohnnyCrazy commented Mar 2, 2021

@smfields Maybe found the culprit. It's related to how we cache type information for query/body params to reduce reflection calls. Since you're already on a local build, could you test out branch params-race-condition-fix?

@smfields
Copy link
Author

smfields commented Mar 2, 2021

@JohnnyCrazy Yup, the fixes made in params-race-condition-fix seem to have resolved this for me.

@JohnnyCrazy
Copy link
Owner

Alright, thanks for the feedback, I will leave the issue open for some days and if I hear nothing, it will be in the next reelase.

Thanks for the report! 😉

@fjmorel
Copy link

fjmorel commented Mar 4, 2021

Hey, I had a similar issue today with q, so I'm glad to hear a fix will be out soon.

System.ArgumentException: An item with the same key has already been added. Key: q
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at SpotifyAPI.Web.RequestParams.AddQueryParam(Dictionary`2 queryParams, PropertyInfo prop, QueryParamAttribute attribute)
   at SpotifyAPI.Web.RequestParams.BuildQueryParams()
   at SpotifyAPI.Web.SearchClient.Item(SearchRequest request)
   at MusicMatching_NSB.Services.SpotifyService.SearchTracksByIsrc(String isrc, Int32 limit, Int32 offset, String market) in /src/Queues/MusicMatching_NSB/Services/SpotifyService.cs:line 140

@JohnnyCrazy
Copy link
Owner

@fjmorel @smfields Just published 6.1.0, so feel free to switch to the nuget version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants