5

I have developed simple Service Bus Trigger with CosmosDB Output with Visual Studio. Connection strings of Service Bus and CosmosDB are defined in local.settings.json. Code is fully function locally. Now I have Zip Published Function(C#) to Azure.

I'm getting Error:

Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. 
Microsoft.Azure.WebJobs.Host: Unable to resolve the value for property 
'CosmosDBAttribute.ConnectionStringSetting'. 

What should I do?

enter image description here

Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
Kenny_I
  • 2,001
  • 5
  • 40
  • 94
  • Please edit your question to include both your code and your error message as properly-formatted text. [This meta post](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557) offers insight into why code and other text shouldn't be published as an image. – David Makogon Mar 14 '20 at 03:32

3 Answers3

7

The error tells you need to add the settings on Azure.

azure function on azure is different from azure functions on local. on local the settings is in the local.settings.json. But on azure it is in the Configuration.(Even if you deploy the local.settings.json, the function will read env settings from Congfiguration)

enter image description here

enter image description here

And dont forget to save your edit.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • 1
    Is there a way to automatically update such values from local.settings.json to application settings during deployment? I read that they have to be part of POM.xml but how do we get it into that file? – Lalman May 16 '20 at 11:44
  • yes, you can upload your local.settings.json file with the code, by default that file didnt gets uploaded. – samtoddler Nov 12 '20 at 15:20
2

I had the same issue in local when running the azure function. My connection string was not accepted because the AccountKey was considered part of the URL of AccountEndpoint, and I gave space between the endpoint of AccountKey and AccountEndpoint.

"connectionStringSetting": "AccountEndpoint=; AccountKey=;"

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "myCosmosDb": "AccountEndpoint=https://mycosmoscosmosdb.documents.azure.com:443/; AccountKey=asd4ph1omRg9Rn4dlj7h1f7XqUdO1mHJcpG9rN1XECSO4P6LKorDXjdqK8VTookKvbKXjPTulpEsdfdsbwg==;"
  }
}
Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
0

In my the extension was missing in host.json:

{
    "version": "2.0",
    "extensions": {
        "cosmosDB": {
            "connectionMode": "Gateway",
            "protocol": "Https",
            "leaseOptions": {
                "leasePrefix": "prefix1"
            }
        }
    }
}

Here the reference: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-output?tabs=csharp#hostjson-settings

Anton
  • 53
  • 3