2

I'm working with Azure functions, trying to get things working with output queues but I keep running into an error with the output binding. I'm wondering if it's something to do with the way I'm decorating the parameters? I've seen how it can be done with using a single queue as a return value, but I have a need to have multiple output queues.

Function definition:

using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Host; using Newtonsoft.Json; using Newtonsoft.Json.Linq;

namespace FunctionApp1 {
    public static class TestItemAddQueueTrigger
    {
        [StorageAccount("AzureWebJobsStorage")]
        [FunctionName("TestItemAddQueueTrigger")]
        public static void Run([QueueTrigger("testitem-add")] string itemAdd,
            TraceWriter log,
            [Queue("testitem-added", Connection = "AzureWebJobsStorage")] out string itemAddedQueue)
        {
            dynamic message = JObject.Parse(itemAdd);

            log.Info($"Received message\n{JsonConvert.SerializeObject(message, Formatting.Indented)}");


            var itemAddedQueueMessage = new
            {
            };

            itemAddedQueue = JsonConvert.SerializeObject(itemAddedQueueMessage);

            log.Info($"Sent message to queue \"itemAddedQueue\"\n{JsonConvert.SerializeObject(itemAddedQueueMessage, Formatting.Indented)}");
        }
    } }

Error Message:

A ScriptHost error has occurred
[10/18/2017 4:31:27 PM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.TestItemAddQueueTrigger'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'itemAddedQueue' to type String&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

Nuget references:

Microsoft.NET.Sdk.Functions (1.0.6) Microsoft.Azure.WebJobs (2.1.0-beta4) Microsoft.Azure.WebJobs.Extensions (2.1.0-beta4)
Microsoft.Azure.WebJobs.Extensions.Http (1.0.0-beta4) Newtonsoft.Json (9.0.1) System.ValueTuple (4.3.0)

Project File:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net47</TargetFramework>
  </PropertyGroup>
  <ItemGroup>    
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.6" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Solution File:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2002
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionApp1", "FunctionApp1\FunctionApp1.csproj", "{10F86A7D-5E03-41A9-8BBB-103C8E06E059}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {10F86A7D-5E03-41A9-8BBB-103C8E06E059}.Release|Any CPU.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {B0A27606-232E-4B58-9586-12AB68E9CAC0}
    EndGlobalSection
EndGlobal
6
  • Try removing out from before string: [Queue("testitem-added", Connection = "AzureWebJobsStorage")] string itemAddedQueue Commented Oct 18, 2017 at 17:08
  • 1
    Your code works just fine for me. Which NuGet packages are you referencing? Commented Oct 18, 2017 at 21:15
  • @AndrésNava-.NET - the 'out' keyword is important. That's the difference between enqueuing a function ([Queue] out string) and triggering on a queue message ([QueueTrigger] string) Commented Oct 18, 2017 at 22:01
  • This is almost guaranteed to be a dll version mismatch. Commented Oct 18, 2017 at 22:04
  • I'm leaning towards a version issue as well. It works on one of my teammates machines just fine I will probably attack it again later this week, just not obvious yet which package would be the issue. Commented Oct 19, 2017 at 12:47

2 Answers 2

3

I was able to resolve this by reinstalling the azure core tools 1.x from npm: npm install -g azure-functions-core-tools

This forced visual studio to reinstall the Azure Cli tools, my best guess is that it was a version conflict somewhere.

Unfortunately I don't know the root cause or combination of versions that caused my issues.

Sign up to request clarification or add additional context in comments.

Comments

0

I've seen how it can be done with using a single queue as a return value, but I have a need to have multiple output queues.

I have used the same function package as you and created a test demo on my side. It works well.

enter image description here

So I suggest you could try to create a new function project and use below codes test again.

This code has multiple output queues. It will auto send the queue to both "output" and "output2".

  public static class Function1
    {
        [StorageAccount("AzureWebJobsStorage")]
        [FunctionName("Function1")]
        public static void Run([QueueTrigger("queue")]string myQueueItem,[Queue("output")] out string test2, [Queue("output2", Connection = "AzureWebJobsStorage")] out string itemAddedQueue, TraceWriter log)
        {
            log.Info($"C# Queue trigger function processed: {myQueueItem}");

            dynamic message = JObject.Parse(myQueueItem);

            log.Info($"Received message\n{JsonConvert.SerializeObject(message, Formatting.Indented)}");


            var itemAddedQueueMessage = new test
            {
                name = "test"
            };

            itemAddedQueue = JsonConvert.SerializeObject(itemAddedQueueMessage);

            test2 = JsonConvert.SerializeObject(itemAddedQueueMessage);

            log.Info($"Sent message to queue \"itemAddedQueue\"\n{JsonConvert.SerializeObject(itemAddedQueueMessage, Formatting.Indented)}");
        }

        public class test
        {
            public string name { get; set; }
        }

    }

The result as below:

enter image description here

1 Comment

Thanks for the feedback, that looks like what I will need to set up for the multiple queues. I'm still getting the same error though when I run this code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.