Search code examples
c#azureazure-functionsazure-storage-queues

How do I debug azure function locally


Hello I have created a function in Azure Portal and seeing the queue data dequeued.

I have installed an CLI on my computer which when I run the project it will show a func.exe command prompt. I have added the connection string like this, inside the local.settings.json:

>  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=...",
    "AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=...",
    "tuxdev_STORAGE": "DefaultEndpointsProtocol=https;AccountName=..."
  } 

When I add a message to the queue in a portal, the application didn't receive the message. What other setting do I need to update.

enter image description here


Solution

  • According to your error message, it seems that the issue is your class or method not public. If I set my method to be private, I also get the same error as you.

    enter image description here

    If I set the function method to be public, everything works fine. The function would show the queue I have added in portal.

    using Microsoft.Azure.WebJobs;
    using Microsoft.Azure.WebJobs.Host;
    
     public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([QueueTrigger("myqueue", Connection = "AzureWebJobsStorage")]string myQueueItem, TraceWriter log)
        {
    
            log.Info($"C# Queue trigger function processed: {myQueueItem}");
        }
    }
    

    enter image description here

    Or the issue may be related with your nuget package versions. you could upgrade to the latest Microsoft.NET.Sdk.Functions (1.0.6 as of today) and Microsoft.Azure.WebJobs.Service.Bus (2.1.0-beta4 if running on full framework). Please refer to this article.

    You should upgrade to the latest Microsoft.NET.Sdk.Functions (1.0.6 as of today) and Microsoft.Azure.WebJobs.Service.Bus (2.1.0-beta4 if running on full framework). You might need to remove ServiceBus reference first in order to upgrade SDK.

    The Microsoft.Azure.Eventhubs package also needs to be removed. All relevant types etc are in Microsoft.Azure.WebJobs.Service.Bus

    Also remember to check "Include prerelease" in the package manager in order to find 2.1.0-beta4