I am trying to use the WebJobs SDK extensions (and the Azure Functions tools for VS) to migrate my Azure functions to pre-compiled binaries, but I'm having problems with the DocumentDB bindings.
I'm trying to create an input binding to an existing DocumentDB document that I can read from, then update the data. When I do this in a script-based Azure function, everything works the way I want. Here's the code I'm using:
public static void Run(TimerInfo myTimer, JObject document, TraceWriter log)
{
log.Info(document.ToString());
var active = document["active"] as JArray;
foreach (var item in active)
{
log.Info($"Polling {item}...");
}
document["processed"] = DateTime.Now;
log.Info(document.ToString());
}
The document in question looks like this:
{
"id": "sites",
"_rid": "(hash)",
"_self": "(stuff)",
"_etag": "\"(guid)\"",
"_attachments": "attachments/",
"active": [
"scifi"
],
"_ts": 1497184149
}
If I try to move this exact code into a pre-compiled function, using WebJobs attributes:
[FunctionName("TimerFeed")]
public static void Run(
[TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
[DocumentDB("FeedStateDatabase", "FeedItemsCollection", ConnectionStringSetting = "feed_DOCUMENTDB", Id = "sites")] JObject document,
TraceWriter log)
then I get an error trying to run the function:
2017-06-11T12:26:36.046 Exception while executing function: Functions.TimerFeed. Newtonsoft.Json: Cannot create and populate list type Newtonsoft.Json.Linq.JToken. Path 'active', line 1, position 219.
Note that the error is thrown before any of my function's code runs. It is thrown even if I remove all of the code and just do a simple diagnostic log. So, I'm pretty sure there's something wrong with my binding. The functions.json
file that is being generated looks off, specifically it's claiming that this is an output binding:
{
"type": "documentDB",
"databaseName": "FeedStateDatabase",
"collectionName": "FeedItemsCollection",
"createIfNotExists": false,
"connection": "feed_DOCUMENTDB",
"id": "sites",
"direction": "out",
"name": "document"
}
dynamic
appears to solve the problem; it actually looks unrelated to the binding direction (at least, the "broken" binding works fine as adynamic
. – Michael Edenfield