The method signature appears to have changed
ExecuteStoredProcedureAsync<TOutput>(string storedProcedureId, PartitionKey partitionKey, [Dynamic(new[] { false, true })] dynamic[] parameters, StoredProcedureRequestOptions requestOptions = null, CancellationToken cancellationToken = default);
Note that the parameters argument is now of type dynamic[] so the newItem object would effectively need to be something like this.
dynamic[] newItem = new dynamic[]
{
new {
category = "Personal",
name = "Groceries",
description = "Pick up strawberries",
isComplete = false
}
};
It'd also be worth renaming the newItem variable to something like payload or args
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@BenWhite27 We are checking this and we will get back to you
@BenWhite27 Thank you for the feedback.
This specific example demonstrates creating a single ToDo item and hence the use of dynamic object arrays is not shown.
You shouldn't run into any compilation errors though.
Hi @KalyanChanumolu-MSFT
I didn't get any compilation errors, but I did get runtime errors with something to the effect of "One or more of the parameters are incorrect".
Just dug this out of my search history...
Anonymously Hosted DynamicMethods Assembly: The best overloaded method match for 'Microsoft.Azure.Cosmos.Scripts.Scripts.ExecuteStoredProcedureAsync'
So it looks like the dynamic runtime couldn't find an overload that matched the parameters I had specified.
@SnehaGunda FYI
@markjbrown I remember you built the initial version of stored procedure samples, can you please confirm that the parameters argument is now of type dynamic[] ?
Mark updated the doc in the above PR. The content will be live by EOD today, we will now close this issue.
@SnehaGunda my storedProcedure works welll in cosmosdb portal by from V3 i still getting errors
dynamic[] newItem = new dynamic[]
{
new {
category = "Personal",
name = "Groceries",
description = "Pick up strawberries",
isComplete = false
}
};
and with this my storedProcedure return
"Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path '', line 1, position 1.\r\n at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)\r\n at Newtonsoft.Json.JsonTextReader.ReadAsString()\r\n at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.DeserializeT\r\n at Microsoft.Azure.Cosmos.CosmosJsonDotNetSerializer.FromStreamT\r\n
im experiencing the same issue as ejdrian313, but it appears that the stored procedure executes as expected, but for now im catching the error and discarding it.
Hope someone has time to look into this :)
Yes so I think the issue is you need to pass the dynamic object in with a new[] { newItem } like this below.
var result = await client.GetContainer("database", "container").Scripts.ExecuteStoredProcedureAsync<string>("spCreateToDoItem", new PartitionKey("Personal"), new[] { newItems });
I updated the sample stored proc to handle array of items and updated the example on this page that uses it. It should get published around 10am Pacific time tomorrow.
Thanks.
Most helpful comment
@SnehaGunda my storedProcedure works welll in cosmosdb portal by from V3 i still getting errors
dynamic[] newItem = new dynamic[]
{
new {
category = "Personal",
name = "Groceries",
description = "Pick up strawberries",
isComplete = false
}
};
and with this my storedProcedure return
"Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path '', line 1, position 1.\r\n at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)\r\n at Newtonsoft.Json.JsonTextReader.ReadAsString()\r\n at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.DeserializeT\r\n at Microsoft.Azure.Cosmos.CosmosJsonDotNetSerializer.FromStreamT\r\n