Closed rakeshbimra closed 1 year ago
Hi @rakeshbimra would you be able to share the full error? Cosmos DB usually logs a JSON body with some more details on the 400 response.
Hi, I tried with another object, now I got to know why this issue is coming:
For example: If I define PartitionKeyPath in Pascal case(as shown in the below object), then it is throwing the error.
[Container("Employee")]
[PartitionKeyPath("/EmployeeId")]
public class Employee : Item
{
[JsonProperty("EmployeeId")]
public string EmployeeId { get; set; }
[JsonProperty("FirstName")]
public string FirstName { get; set; }
[JsonProperty("LastName")]
public string LastName { get; set; }
protected override string GetPartitionKeyValue() => EmployeeId;
}
When I am trying to add new item for above object I am getting below error:
Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: BadRequest (400); Substatus: 1001; ActivityId: 62f88a7a-952f-41ef-9bd3-1c09df77df0d; Reason: ();
at Microsoft.Azure.Cosmos.ResponseMessage.EnsureSuccessStatusCode()
at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.ProcessMessage[T](ResponseMessage responseMessage, Func2 createResponse) at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.CreateItemResponse[T](ResponseMessage responseMessage) at Microsoft.Azure.Cosmos.ContainerCore.CreateItemAsync[T](T item, ITrace trace, Nullable
1 partitionKey, ItemRequestOptions requestOptions, CancellationToken cancellationToken)
at Microsoft.Azure.Cosmos.ClientContextCore.RunWithDiagnosticsHelperAsync[TResult](ITrace trace, Func2 task) at Microsoft.Azure.Cosmos.ClientContextCore.OperationHelperWithRootTraceAsync[TResult](String operationName, RequestOptions requestOptions, Func
2 task, TraceComponent traceComponent, TraceLevel traceLevel)
at Microsoft.Azure.CosmosRepository.DefaultRepository1.CreateAsync(TItem value, CancellationToken cancellationToken) at Microsoft.Azure.CosmosRepository.DefaultRepository
1.CreateAsync(IEnumerable1 values, CancellationToken cancellationToken) at lambda_method5(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.
I deleted Employee container and I tried PartitionKeyPath name with camel case it is working fine.
[Container("Employee")]
[PartitionKeyPath("/employeeId")]
public class Employee : Item
{
[JsonProperty("employeeId")]
public string EmployeeId { get; set; }
[JsonProperty("FirstName")]
public string FirstName { get; set; }
[JsonProperty("LastName")]
public string LastName { get; set; }
protected override string GetPartitionKeyValue() => EmployeeId;
}
So is this library only supporting PartitionKeyPath name in camel case?
Okay I think @IEvangelist ran into this problem as well a few months back.
Have you tried setting the serialised options on RepositoryOptions
if you see here https://github.com/IEvangelist/azure-cosmos-dotnet-repository/blob/fe87219fd93cd28087f92473e1bafae055f6378f/src/Microsoft.Azure.CosmosRepository/Options/RepositorySerializationOptions.cs#L31
It defaults to camel case unless overridden.
I tried but still getting the same issue
builder.Services.AddCosmosRepository(options =>
{
options.SerializationOptions = new Microsoft.Azure.CosmosRepository.Options.RepositorySerializationOptions
{
PropertyNamingPolicy = Microsoft.Azure.Cosmos.CosmosPropertyNamingPolicy.Default
};
});
Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: BadRequest (400); Substatus: 1001; ActivityId: af83319b-ef2b-4abc-93ec-357f214a1f48; Reason: ();
at Microsoft.Azure.Cosmos.ResponseMessage.EnsureSuccessStatusCode()
at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.ProcessMessage[T](ResponseMessage responseMessage, Func2 createResponse) at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.CreateItemResponse[T](ResponseMessage responseMessage) at Microsoft.Azure.Cosmos.ContainerCore.CreateItemAsync[T](T item, ITrace trace, Nullable
1 partitionKey, ItemRequestOptions requestOptions, CancellationToken cancellationToken)
at Microsoft.Azure.Cosmos.ClientContextCore.RunWithDiagnosticsHelperAsync[TResult](ITrace trace, Func2 task) at Microsoft.Azure.Cosmos.ClientContextCore.OperationHelperWithRootTraceAsync[TResult](String operationName, RequestOptions requestOptions, Func
2 task, TraceComponent traceComponent, TraceLevel traceLevel)
at Microsoft.Azure.CosmosRepository.DefaultRepository1.CreateAsync(TItem value, CancellationToken cancellationToken) at Microsoft.Azure.CosmosRepository.DefaultRepository
1.CreateAsync(IEnumerable1 values, CancellationToken cancellationToken) at lambda_method5(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.
We have serious trouble about it as well. Further more, the JsonProperty is not overrided what we are excpecting. To be clear, How can we use the default serializer with camelCase default options and taking the JsonProperty in account ?
How can we do that ??
var jsonSerializerSettings = new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() },
}
Because in our legacy model, we have a mixed of PascalCase and camelCase properties.
It starated working when I am using CosmosPropertyNamingPolicy.Default
builder.Services.AddCosmosRepository(options =>
{
options.SerializationOptions = new Microsoft.Azure.CosmosRepository.Options.RepositorySerializationOptions
{
PropertyNamingPolicy = CosmosPropertyNamingPolicy.Default
};
});
Closing this issue, as the matter of configuring serialization is the known solution.
While creating new item I am getting below error
"Response status code does not indicate success: BadRequest (400); Substatus: 1001; ActivityId: 68af0c72-ff2d-4055-8898-b94a08f18ead; Reason: ();"
Stack Trace:
at Microsoft.Azure.Cosmos.ResponseMessage.EnsureSuccessStatusCode() at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.ProcessMessage[T](ResponseMessage responseMessage, Funcd__7.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Threading.Tasks.ValueTaskd__2.MoveNext() in C:\notification-subscribers\dev\Notification-Microservices\CardGroupEventSubscriber\CardGroupEventSubscriber\Publishers\UINotificationPublisher.cs:line 49
2 createResponse) at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.CreateItemResponse[T](ResponseMessage responseMessage) at Microsoft.Azure.Cosmos.ContainerCore.<CreateItemAsync>d__54
1.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Azure.Cosmos.ClientContextCore.<RunWithDiagnosticsHelperAsync>d__39
1.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.Azure.Cosmos.ClientContextCore.<OperationHelperWithRootTraceAsync>d__30
1.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Azure.CosmosRepository.DefaultRepository
1.1.get_Result() at System.Runtime.CompilerServices.ValueTaskAwaiter
1.GetResult() at CardGroupEventSubscriber.Publishers.UINotificationPublisher.Below is my code:
public class UINotificationPublisher : IUINotificationPublisher {