Azure Function Failing to Bind to CosmosDb

Simon Painter 31 Reputation points
2020-06-05T18:51:56.277+00:00

I'm following the instructions in this tutorial here:

https://learn.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
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,252 questions
0 comments No comments
{count} vote

Accepted answer
  1. Walter Tudorin 101 Reputation points
    2020-06-07T02:58:55.847+00:00

    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.

    5 people found this answer helpful.

0 additional answers

Sort by: Most helpful