question

SimonPainter-8419 avatar image
1 Vote"
SimonPainter-8419 asked ·

Azure Function Failing to Bind to CosmosDb

I'm following the instructions in this tutorial here:

https://docs.microsoft.com/en-gb/learn/modules/chain-azure-functions-data-using-bindings/5-read-data-with-input-bindings-portal-lab?pivots=javascript

But every time I run the function, it fails with an HTTP 500 response code. Looking in Monitor, this is the error message:

Can't bind CosmosDB to type 'System.String'. Possible causes: 1) Tried binding to 'Microsoft.Azure.Documents.Client.DocumentClient, Microsoft.Azure.DocumentDB.Core, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' but user type assembly was 'System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.


I've tried re-doing the tutorial numerous times, but always with the same result. This is my function.jason file:

{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "bookmark",
"databaseName": "func-io-learn-db",
"collectionName": "Bookmarks",
"connectionStringSetting": "sjp820818_DOCUMENTDB",
"id": "{Id}",
"partitionKey": "{id}",
"sqlQuery": "",
"direction": "in",
"type": "cosmosDB"
}
]
}


Does anyone have any idea what I might be doing wrong?

Thanks,

Simon

azure-functions
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

WalterTudorin-6819 avatar image
4 Votes"
WalterTudorin-6819 answered ·

Hi, I had the same problem and solved it as:
- In the function.json I removed the sqlQuery line.
- I actually had a point where the CosmoDB "direction" was missing (???) so I entered it again and moved the entire block of cosmoDB up in the json structure as:.

{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": [
"get",
"post"
]
},
{
"direction": "in",
"type": "cosmosDB",
"connectionStringSetting": "wtudorin_DOCUMENTDB",
"name": "bookmark",
"databaseName": "func-io-learn-db",
"collectionName": "Bookmarks",
"id": "{id}",
"partitionKey": "{id}"
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
]
}

I went back to "Integration" page and clicked on CosmoDB Input and it appeared that all settings were missing so I re-entered them as listed in the function.json.

After that it all worked.

9224-cosmodbinput.png






Also to be sure I Stopped and Started the Function-App as well.


cosmodbinput.png (36.7 KiB)
· 3 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I think the stopping and starting of the function while carrying out the amendment to the function.json file were the crucial step I was missing.

Thanks everyone!

1 Vote 1 ·

Thanks - I was having the same issue - removing the sqlQuery line fixed it - I didn't have to move the cosmosdb binding block up in the.

0 Votes 0 ·

Thanks, @WalterTudorin-6819 and @MarkFreeman-3682!


@SimonPainter-8419 could you try this out and see if it resolves the issue on your end?


0 Votes 0 ·