Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

VS 2017 Tooling for Functions App is not working in Service Bus Queue based trigger

Open thuru-zz opened this issue 9 years ago • 22 comments

I'm using VS 2017 Enterprise 15.3.3 with Azure Functions and Web Job Tools extension 15.0.30812.0.

There are some issues and observations.

I create the Azure Functions project and without adding any functions, I could update NuGet packages. This updates the package Microsoft.NET.Sdk.Functions 1.0.0 to 1.0.2. Then I add a Service Bus Queue Trigger function, which adds the below code. (I specified the parameter names in the dialog box)

public static class TemperatureSpike
    {
        [FunctionName("TemperatureSpike")]
        public static void Run([ServiceBusTrigger("temperature", AccessRights.Manage, Connection = "TemperatureBus")]string myQueueItem, TraceWriter log)
        {
            log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
        }
    }

Observation 1 : VS automatically downgrades the package back 1.0.0 I have to again manually update the packages 1.0.2

I publish the app using VS. I browsed through the function.json in the portal. It doesn't have the direction parameter in the json. Without this I cannot switch to the standard view of the function.json in the portal.

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "serviceBusTrigger",
      "connection": "TemperatureBus",
      "queueName": "temperature",
      "accessRights": "manage",
      "name": "myQueueItem"
    }
  ],
  "disabled": false,
  "scriptFile": "..\\bin\\Test.dll",
  "entryPoint": "Test.Function1.Run"
}

Observation 2: The function.json still shows the version as Microsoft.NET.Sdk.Functions-1.0.0.0

Observation 3 The bindings section does not have the 'direction' property. Unless I specify the 'direction' I cannot switch to the Standard Editor mode of the function.json in portal.

I configured the connection string in the Function App Settings.

Finally, the trigger does not work. I have tired different combinations of version with 1.0.0 as well but the triggers generated from the VS tooling is not working.

thuru-zz avatar Sep 03 '17 13:09 thuru-zz

Today I got an another update to the Tools - 15.0.30901.0

In this my above observation 1 is solved as the project template refers the package Microsoft.NET.Sdk.Functions 1.0.2

But when i deploy the application to Azure the function.json still says it's 1.0.0.0 The only difference the header details in the bottom :)

Still the direction property is missing in the bindings section and without that we cannot switch to the standard view. And mainly the trigger DOES NOT WORK

{
  "bindings": [
    {
      "type": "serviceBusTrigger",
      "connection": "massroverservicebus_RootManageSharedAccessKey_SERVICEBUS",
      "queueName": "temperature",
      "accessRights": "Manage",
      "name": "myQueueItem"
    }
  ],
  "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
  "configurationSource": "attributes",
  "disabled": false,
  "scriptFile": "..\\bin\\FunctionApp1.dll",
  "entryPoint": "FunctionApp1.Function1.Run"
}

thuru-zz avatar Sep 06 '17 13:09 thuru-zz

I am using Microsoft.NET.Sdk.Functions 1.0.6 and still facing the same issue.

I am also unable to explicitly add the Microsoft.Azure.WebJobs.ServiceBus package due to the version conflict of Microsoft.Azure.WebJobs package.

Is anyone from development team keen to look at this issue?

thucnguyen77 avatar Oct 18 '17 00:10 thucnguyen77

@fabiocav could someone take a look please?

mlorbetske avatar Nov 07 '17 00:11 mlorbetske

I have a workaround to fix the issue with the broken function.json. When using VS to publish an app function to Azure, the function.json omits the "direction" property. For Service Bus Triggers (and other queue triggered functions), this breaks functionality. Recently I discovered that Azure no longer allows me to change the published function to Read/Write, thus preventing me from fixing the function.json file in Azure. I assume other people have the same issue.

There is another way to fix the file.

  1. In Azure, open the App Service blade and Stop the function.
  2. Open the Platform Features tab and start the App Service Tools, under the Development section.
  3. Search the directory structure to locate the function.json file. Mine is shown under the function name.
  4. Edit the file to add the missing "direction": property. The file will autosave.
  5. Close the window and restart the app under the App Service blade.
  6. When the function is started you can select it and see the modified function.json.
  7. If this is the first time you've set up the app function you will need to set the service bus connections, etc. There are plenty of tutorials to tell you how to do this in Azure. I set the connection string under Application Settings, and then connected my app function to the Service Bus Queue using the Integrate tab.

Job done.

Hope this helps. It took me quite a while to figure out how to fix the problem. I hope it is useful for other people.

WayneMcRae avatar Nov 08 '17 10:11 WayneMcRae

@WayneMcRae You really put some hope in my tests, but unfortunately for me this workaround didn't work. =/ Thanks for sharing your way to fix the problem.

I've already tried to replicate the function.json configuration that I have in another AzureFunction that I've created in Azure portal and this other one works just fine.

Does anyone know if there's a way that I could see/log "the errors"? I'm still shooting in the dark with this problem.

hdsmachado avatar Nov 08 '17 21:11 hdsmachado

I had the same problem and I sorted out by changing manually the function.json and set the configurationSource to config:

{ "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.6", "configurationSource": "config", "bindings": [ { "type": "serviceBusTrigger", "connection": "eventHubConnectionString", "queueName": "alertqueue", "accessRights": "manage", "name": "myQueueItem", "direction": "in" } ], "disabled": false, "scriptFile": "../bin/FunctionApp.dll", "entryPoint": "FunctionApp.ServiceBusAlert.Run" }

FAlmeidaActionpoint avatar Nov 21 '17 15:11 FAlmeidaActionpoint

We're experiencing the same issue with the trigger for Service Bus Topic subscription, when using the VS2017 tools. The generated function.json is never correct. Manually changing both the direction + configurationSource settings as described by @FAlmeidaActionpoint and @WayneMcRae solve this. However this is not usable in real world as every time the function is published it will re-generate the wrong file and we need to manually correct it.

katriendg avatar Jan 16 '18 12:01 katriendg

This workaround really works! Thanks @FAlmeidaActionpoint

I hope that this issue could be solved soon, because every time that I need to change or publish any function I have to go and change every single "function.json"

hdsmachado avatar Jan 17 '18 16:01 hdsmachado

@katriendg @hdsmachado Could you check to make sure that you have defined the service bus connection string for the published version within the Azure portal? (Click on the function app name => Application settings).

I think that the missing connection string in the published version may be the root cause of the issue. Although changing configurationSource to "config" links the app to the connection string defined locally, it isn't the best solution (as I'm sure you all know too well).

If you can confirm that this is the issue, we need to change the missing connection string error to have a more informative error message. Otherwise, I'll keep investigating!

image image

mhoeger avatar Jan 19 '18 23:01 mhoeger

I am having similar issue. I have created all the app settings on the azure portal. No luck :-(. Had to manually edit function.json to get it working. (This gets hard to achieve automation through continuous build and needs manual intervention).

Infoseeker avatar Feb 02 '18 12:02 Infoseeker

@Infoseeker There is a bug where the wrong function.json gets generated without a clean build before publish (#664). Could you try doing clean, then build, then publish?

If that doesn't work, would you mind sharing more details about what's going on? For example, the trigger type, exact error messages, and your function name so that we can investigate (you can also share it privately following these instructions: https://github.com/Azure/azure-functions-host/wiki/Sharing-Your-Function-App-name-privately)

mhoeger avatar Feb 03 '18 01:02 mhoeger

We're experiencing the same issue with the trigger for Service Bus Topic subscription, when using the VS2017 tools. The generated function.json is never correct. Manually changing both the direction + configurationSource settings as described by @FAlmeidaActionpoint and @WayneMcRae solve this. However this is not usable in real world as every time the function is published it will re-generate the wrong file and we need to manually correct it.

It worked. Still this issue is not fixed in visual studio 17

vinayakmali84 avatar Nov 18 '18 14:11 vinayakmali84

@vinayakmali84 - The fix should have been released in the tooling for Visual Studio a while ago but your tools may be out of date. Can you try making sure that your Azure Functions and Web Jobs Tools is updated?

mhoeger avatar Nov 19 '18 17:11 mhoeger

I'm running the latest release of Azure Functions and an up to date version of VS2017 Pro. Still have this problem when I publish my functions to Azure. I have to manually add "direction": "in" to function.json when I publish.

WayneMcRae avatar Nov 20 '18 11:11 WayneMcRae

@vinayakmali84 - The fix should have been released in the tooling for Visual Studio a while ago but your tools may be out of date. Can you try making sure that your Azure Functions and Web Jobs Tools is updated?

I am using latest version on Visual Studio 2017 V: 15.9.1 I am using latest version of Azure Function, when I published app first time, it asked me to update it. Still issue is not resolved. I need to do manual modification of "direction" & set connection string config in json

vinayakmali84 avatar Nov 20 '18 18:11 vinayakmali84

A few releases have gone out since this issue was created. Does this still occur?

jeffhollan avatar Feb 27 '19 07:02 jeffhollan

It is still happening for me. Azure Functions and Web Jobs Tools (15.10.2046.0; 17/10/2018) and Visual Studio 2017 (Version 15.9.7; VisualStudio.15.Release/15.9.7+28307.423; Microsoft .NET Framework; Version 4.7.03190) My project is targeting .NET Framework 4.6.1. The project originally published the correct function.json. None of the updates have fixed the issue. I haven't tried it with VS 2019 yet. 2019 is still in RC and it's a little too early to trust with production code, in my opinion.

WayneMcRae avatar Feb 27 '19 09:02 WayneMcRae

@WayneMcRae - can you check the version of Microsoft.NET.Sdk.Functions in installed nuget packages? It should be >= 1.0.8.

image

mhoeger avatar Feb 27 '19 22:02 mhoeger

Ah, that worked. I was still using 1.0.7. After upgrading to 1.0.25 it is working fine. Thank you, Marie. I really appreciate your help.

WayneMcRae avatar Feb 28 '19 09:02 WayneMcRae

No problem @WayneMcRae :) Glad your issue is resolved!!

Closing this issue - if anyone is still experiencing it, please check the version of Microsoft.NET.Sdk.Functions in installed nuget packages. It should be >= 1.0.8.

image

mhoeger avatar Feb 28 '19 23:02 mhoeger