System.ArgumentException: An item with the same key has already been added. Key: xyz
See original GitHub issueI’ve created this sample repo to demonstrate the exception outlined in the subject line. The details of the issue have been described in the README.md file of that repo.
Would you please share a solution because renaming public MyRequest Request { get; set; }
in both MySubmittedData
and YourSubmittedData
classes is not feasible? Doing so will lead to other complexities and break the code’s architecture (outside of this repo).
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
An item with the same key has already been added
An item with the same key has already been added. And the exception details: [ArgumentException: An item with the same key has already...
Read more >An Item With the Same Key Has Already Been Added
An item with the same key has already been added error happens when the model has the same property twice. Click here to...
Read more >An item with the same key has already been added c# MVC
So start by looking at the error message: An item with the same key has already been added.
Read more >Error "An item with the same key has already been added"
This scenario typically occurs if an operating system image is being used to deploy cluster nodes and that image was not correctly prepared...
Read more >An item with the same key has already been added Error
The error reads: "An item with the same key has already been added." It does not matter if I include the database name...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Seems like what is needed is a configuration setting and functionality similar to CustomSchemaIds as implemented here: https://github.com/domaindrivendev/Swashbuckle.AspNetCore#customize-schema-ids.
I have the same issue with nested generic types. Downgrading to 1.0.0 doesn’t fix it for me either.
Having these combined fails for me with the error message:
An item with the same key has already been added. Key: Response_list
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: MediaTypeNames.Application.Json, bodyType: typeof(Response<List<Version>>))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: MediaTypeNames.Application.Json, bodyType: typeof(Response<List<Endpoint>>))]
I worked around the issue by changing the body types to
Response<Version[]>
andResponse<Endpoint[]>