I have recently moved to Azure Functions with .NET 5 (dotnet-isolated). I experienced an exception using an output binding to CosmosDb that was hard to debug. I'm going to post the answer below for further reference.
First, the function was straight forward but with a rather complex return type.
[Function(nameof(StationStore))]
[CosmosDBOutput(
databaseName: "%Database%",
collectionName: "%Collection%",
CreateIfNotExists = true,
ConnectionStringSetting = "CosmosDbConnectionString")]
public CosmosModel Run(
[ServiceBusTrigger("%Queue_Storage%", Connection = "ServiceBusConnection")]
StoreModel metaModel,
// Trigger not relevant for question
FunctionContext context)
{
// code omitted, doesn't matter for question
return new CosmosModel();
}
I got this exception after code execution, so not stack trace and no way to set a breakpoint.
System.Private.CoreLib: Exception while executing function: Functions.StationStore. Microsoft.Azure.DocumentDB.Core: Value cannot be null. (Parameter 'document').
Because the return parameter was properly set the message seems very strange.