'i am receiving an error while returning `<IEnumerable<RiskValue>`.. ASP.NET [closed]
var result = JsonConvert.DeserializeObject<Risks>(jsonData);
var finalResult = result.Value.Where(x => x.ID == 5).ToList();
return finalResult;
I am working on an API that returns <IEnumerable<RiskValue>
the deserializing does not cause any error this error is shown when I return the final result, any idea of what causing this?
System.InvalidOperationException: The JSON property name for 'MyProject.Models.RisksValue.ID' collides
with another property.
System.InvalidOperationException: The JSON property name for 'test_1.Models.RisksValue.ID' collides with another property.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerPropertyNameConflict(Type type, JsonPropertyInfo jsonPropertyInfo)
Solution 1:[1]
Try to set PropertyNameCaseInsensitive
to false
in your Startup.cs:
services.AddControllers().AddJsonOptions(options => {
options.JsonSerializerOptions.PropertyNamingPolicy = null;
//the importance here..
options.JsonSerializerOptions.PropertyNameCaseInsensitive = false;
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Rena |