Reputation: 655
I created Azure Function (2.0v) from C# HTTP template . Then I added output binding to CosmosDB based on CosmosDB docs:
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() };
}
}
Packages, that I use (csproj file):
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.0-beta7" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.11" />
This is my local.settings.json. I based them on values from CosmosDB emulator:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "",
"myCosmosDB": "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
}
}
Unfortunately, when I hit HTTP trigger I get:
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.
What does this exception means? I cannot find any relevant information about it and it completely stops my local work. Function works well without CosmosDB attribute.
Upvotes: 2
Views: 975
Reputation: 17790
It should be a breaking change in new cli. Try to downgrade cli to 2.0.1-beta.25
, it works on my side. BTW, I recommend you to update Microsoft.NET.Sdk.Functions
to 1.0.13
to avoid possible exception.
beta.24
seems outdated and also causes Method not found
error on my side. While beta.26
leads to error same as beta.28
.
However, if I debug the project directly using VS(which uses beta.26 no-runtime version) or publish it to Azure, works fine. Have opened an issue on github, you can track it if interested.
Update
Solved in 2.0.1-beta.29
, runtime 2.0.11857.0
.
Upvotes: 2
Reputation: 12538
This was a regression with the latest version (2.0.11776) of the host. This has been addressed and the release is currently in progress.
Upvotes: 4
Reputation: 222522
What version of the DocumentDB package are you referencing?
Recommendation would be to either:
downgrade any DocumentDB nuget to 1.13.2.
Remove the DocumentDB reference completely and instead directly reference Microsoft.Azure.WebJobs.Extensions.DocumentDB, which will reference the correct version for you.
Upvotes: -1