Recently, I was building an Azure Function from Visual Studio and encountered an issue with the auto generated Function.cs class file.
My requirement was to create an Azure Function that would get triggered as soon as we receive a message on an Azure Service Bus Topic. For this I tried to use the Project template available in Visual Studio 2017.
Unfortunately, when I tried to provide all the required values, and run the function, I got following error:
First you get a warning which says:
Warning: Cannot find value named 'Endpoint=sb:......' in local.settings.json that matches 'connection' property set on 'serviceBusTrigger' in '\Source\repos\FunctionApp1\MyFunction\bin\Debug\net461\Function1\function.json'. You can run 'func azure functionapp fetch-app-settings <functionAppName>' or specify a connection string in local.settings.json.
This warning was followed by an error:
[2/12/2018 9:48:05 AM] A ScriptHost error has occurred
[2/12/2018 9:48:05 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1.Run'. Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsEndpoint=sb:....' is missing or empty.
[2/12/2018 9:48:05 AM] Error indexing method 'Function1.Run'
[2/12/2018 9:48:05 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1.Run'. Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsEndpoint=sb:/.....' is missing or empty.
My requirement was to create an Azure Function that would get triggered as soon as we receive a message on an Azure Service Bus Topic. For this I tried to use the Project template available in Visual Studio 2017.
Unfortunately, when I tried to provide all the required values, and run the function, I got following error:
First you get a warning which says:
Warning: Cannot find value named 'Endpoint=sb:......' in local.settings.json that matches 'connection' property set on 'serviceBusTrigger' in '\Source\repos\FunctionApp1\MyFunction\bin\Debug\net461\Function1\function.json'. You can run 'func azure functionapp fetch-app-settings <functionAppName>' or specify a connection string in local.settings.json.
This warning was followed by an error:
[2/12/2018 9:48:05 AM] A ScriptHost error has occurred
[2/12/2018 9:48:05 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1.Run'. Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsEndpoint=sb:....' is missing or empty.
[2/12/2018 9:48:05 AM] Error indexing method 'Function1.Run'
[2/12/2018 9:48:05 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1.Run'. Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsEndpoint=sb:/.....' is missing or empty.
When I tried to look for the issue on the web, I could not find a proper solution for my issue. After exploring further, I finally got the fix for this issue. Hence, I thought of sharing the fix with others, who might face similar issues in their projects.
So whenever we create a new function from inside of Visual Studio 2017, we are required to specify the Azure Service Bus Connection string, the topic and subscription name in a dialog box that appears just like one below:
So whenever we create a new function from inside of Visual Studio 2017, we are required to specify the Azure Service Bus Connection string, the topic and subscription name in a dialog box that appears just like one below:
After we enter the required details and hit OK, we get a Function file that's auto-generated for us by the Functions SDK.
That looks something like this:
And the local.settings.json file looks like this:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"AzureWebJobsDashboard": "",
}
}
The auto-generated code has an issue over here, the value of Connection parameter in the Function File, needs to have the name of the settings Key, which holds the actual connection string.
So in order to get rid of the error, we need to make two changes in the auto-generated code:
- Introduce a setting entry in local.settings.json file, which holds the actual connection string of Azure Service Bus. So your local.settings.json file should look like this:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "Your Storage Account Connection String",
"AzureWebJobsDashboard": "Your Storage Account Connection String",
"MyConnectionKey":"Your Azure Service Bus Connection String"
}
}
- Update the Function file to hold name of the Settings Key that you have declared in local.settings.json, rather than the actual connection string.
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.ServiceBus.Messaging;
namespace MyFunction
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([ServiceBusTrigger("testtopic", "testsubscription", AccessRights.Manage, Connection = "MyConnectionKey")]string mySbMsg, TraceWriter log)
{
log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
}
}
}
Now if you run your Project, you would not get the error again, and your Functions App would work as expected.
Hope this is helpful. Happy Coding :)
Nice blog provided by you and it very informative. No words to explain simply super. And keep update with us Azure Online Training Bangalore
ReplyDeletekayseriescortu.com - alacam.org - xescortun.com
ReplyDeleteSmm panel
ReplyDeletesmm panel
İŞ İLANLARI
İNSTAGRAM TAKİPÇİ SATIN AL
hirdavatciburada.com
beyazesyateknikservisi.com.tr
servis
tiktok jeton hilesi