Reputation: 6121
I have created this stored procedure in a collection in my DocumentDb Account.
I am having trouble executing this with the .NET SDK, here is my code.
dynamic[] procParams = new dynamic[] { "myid", "{ $set: { status : 'Draft' } }" };
return await _client.ExecuteStoredProcedureAsync<Listing>(UriFactory.CreateStoredProcedureUri("dbName", "collection", "update"), procParams);
The SDK throws an ArgumentException:
"Cannot Serialize object if it is not document or attachment"
Seems like I can only pass Document's or Attachments which doesn't seem right? I came across this blog post and it looks like this guy is doing the same but with no issues.
So how do I pass basic parameters to a stored procedure such as strings?
Upvotes: 1
Views: 591
Reputation: 8119
To clarify - it looks like that the exception above refers to an issue with de-serializing the stored procedure's response in to the Listing
class (as opposed to referring to serializing the input parameter before executing the stored procedure).
You can verify whether this is true by examining the response of the stored procedure as a string:
var sprocResponse = client.ExecuteStoredProcedureAsync<string>(UriFactory.CreateStoredProcedureUri("dbName", "collection", "update"), procParams).Result.Response.ToString();
If you are able to retrieve the updated document response as a string; than that means the stored procedure successfully executed and should confirm the issue lies with de-serializing the stored procedure response in to the Listing
class.
A common mistake here is for POCOs to extend the Document class (as opposed to the Resource class: Microsoft.Azure.Documents.Resource
). Please make sure Listing
does not extend Document
, and that the response from the stored procedure can be de-serialized to the Listing
class.
Upvotes: 3