【发布时间】:2018-06-04 12:55:02
【问题描述】:
我从 C# HTTP 模板创建了 Azure Function (2.0v)。然后我添加了基于CosmosDB docs的输出绑定到CosmosDB:
public static class AddEvent
{
[FunctionName("AddEvent")]
public static void Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]
HttpRequest req,
[CosmosDB("SomeDatabase", "SomeCollection", Id = "id",
ConnectionStringSetting = "myCosmosDB", CreateIfNotExists = true)]
out dynamic document)
{
document = new { Text = "something", id = Guid.NewGuid() };
}
}
我使用的包(csproj 文件):
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.0-beta7" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.11" />
这是我的 local.settings.json。我基于 CosmosDB 模拟器中的值:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "",
"myCosmosDB": "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
}
}
不幸的是,当我点击 HTTP 触发器时,我得到:
System.Private.CoreLib: Exception while executing function: AddEvent.
Microsoft.Azure.WebJobs.Host: Exception binding parameter 'document'.
Microsoft.Azure.DocumentDB.Core: The type initializer for 'Microsoft.Azure.Documents.UserAgentContainer' threw an exception.
Object reference not set to an instance of an object.
这个异常是什么意思?我找不到任何相关信息,它完全停止了我的本地工作。函数在没有 CosmosDB 属性的情况下运行良好。
【问题讨论】:
-
看起来类似于this issue。你有哪个确切的版本?
-
问题已在 29 cli 中解决。您可以接受一个答案来结束此问题。
标签: azure azure-functions azure-cosmosdb