0
votes

I have a simple C# HttpTrigger Azure function that retrieves data from CosmosDB:

namespace urda
{
    public static class GetAccount
    {
        [FunctionName("GetAccount")]
        public static IActionResult Run(
            [HttpTrigger(
                AuthorizationLevel.Anonymous, 
                "get", 
                Route = "account/{id}")] HttpRequest req,
            [CosmosDB(
                "UrdaDemo", 
                "Accounts",
                ConnectionStringSetting = "CosmosDBConnection",
                SqlQuery = "select * from Accounts a where a.id = {id}")]
                IEnumerable<Account> accounts,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            foreach (Account account in accounts)
            {
                log.LogInformation(account.id);
            }
            return new OkObjectResult(accounts);
        }
    }
}

The function worked fine until a few days ago (last checked on Nov. 22) and now it does not. It gives me the following error?

Function (Urda/GetAccount) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'GetAccount'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'accounts' to type IEnumerable`1. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

I have not changed anything nor redeployed the function and am not sure why I am getting this error? What is meant by "make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage()..."?

1
i suspect this may be a case of an error message that is masking a problem connecting to CosmosDB. Can you confirm you have a “CosmosDBConnectoin” app setting and that it still has a valid connection string? I asssume if you had this working before you have installed the Microsoft.Azure.WebJobs.Extensions.CosmosDb extension as well into the project so your app “knows” how to talk to Cosmos?jeffhollan

1 Answers

0
votes

I recreated and redeployed the functions using Visual Studio and it worked fine. Upon comparison of the artifacts, the only difference between my Visual Studio Code project and Visual Studio project I found was in host.json:

{
    "version": "2.0",
-    "extensionBundle": {
-        "id": "Microsoft.Azure.Functions.ExtensionBundle",
-        "version": "[1.*, 2.0.0)"
-    }
}

Lines marked with a "-" were no longer needed. That fixed the problem. BUt on previous deployments, these lines were there and all was good. Go figure.