2017-08-12 71 views
2

升級到1.0.1 CLI工具,無需更改任何代碼後,我突然開始出現以下錯誤:Azure的功能SDK

ResizeImage: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ResizeImage'. 
Microsoft.Azure.WebJobs.Extensions.DocumentDB: 
'Id' is required when binding to a DocumentClient property. 

下面的代碼:

[FunctionName(nameof(ResizeImage))] 
public static async Task RunAsync([BlobTrigger("profile-pictures/{name}")] CloudBlockBlob myBlob, string name, [DocumentDB(databaseName: "x", collectionName: "UserProfile", CreateIfNotExists = true)] DocumentClient client, [Blob("profile-pictures/resized-{name}", FileAccess.ReadWrite)] CloudBlockBlob resizedBlob, TraceWriter log) 

我認爲Id是可選的?至少這就是文檔所說的。

根據文檔:

The properties id and sqlQuery cannot both be specified. If neither id nor sqlQuery is set, the entire collection is retrieved.

生成的JSON:

{ 
    "bindings": [ 
    { 
     "type": "blobTrigger", 
     "path": "profile-pictures/{name}", 
     "direction": "in", 
     "name": "myBlob" 
    }, 
    { 
     "type": "documentDB", 
     "databaseName": "x", 
     "collectionName": "UserProfile", 
     "createIfNotExists": true, 
     "direction": "out", 
     "name": "client" 
    }, 
    { 
     "type": "blob", 
     "path": "profile-pictures/resized-{name}", 
     "direction": "inout", 
     "name": "resizedBlob" 
    } 
    ], 
    "disabled": false, 
    "scriptFile": "..\\X.Functions.dll", 
    "entryPoint": "X.Functions.ResizeImage.RunAsync" 
} 

我使用1.0.0 SDK

回答

0

I thought Id is optional? At least that's what the docs says.

是,ID是可選的。但根據Azure Functions Cosmos DB bindings的文件。我們需要使用IEnumerable < dynamic>作爲綁定類型。請按以下方式更改您的代碼。

[DocumentDB(...)] IEnumerable<dynamic> documents 

您將從集合中獲取所有文檔。我測試了它,它在我身邊運行得很好。

另外,如果你想從DocumentDB獲取數據,方向應該改爲in。

"direction": "in" 
+0

感謝您的迴應,但我不能修改生成的json,因爲我使用SDK根據我的函數的屬性和類型定義來生成它。 –

+0

您是否已將綁定類型更改爲IEnumerable 並且能解決您的問題? – Amor

+0

是的,它沒有。這顯然是一個已知的錯誤,將來會被修復。 –