1

I am attempting to create a web job that runs on a manual trigger (using .Net Core 2.1 and Azure SDK 3.x). I am simply copying/pasting the code from the example (Manual Trigger) to just get a working starting point. However, when I run the sample (locally as well as on my test server in Azure), I get this error:

'CreateQueueMessage' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?'

I have created the azure web job (.Net Core console app) just as it describes in the docs, and I am using the manual trigger (and host) code from the examples verbatim. Is this a bug, or is there something else I need to do?

Here are the docs: https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#triggers

Here is the code I am using in my project:

using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace PubSubTrigger
{
    class Program
    {
        [NoAutomaticTrigger]
        public static void CreateQueueMessage(ILogger logger, string value, Queue("outputqueue")] out string message)
        {
            message = value;
            logger.LogInformation("Creating queue message: ", message);
        }
        static async Task Main(string[] args)
        {
            var builder = new HostBuilder();
            builder.ConfigureWebJobs(b =>
            {
                b.AddAzureStorageCoreServices();
                b.AddAzureStorage();
            });
            var host = builder.Build();
            using (host)
            {
                var jobHost = host.Services.GetService(typeof(IJobHost)) as JobHost;
                var inputs = new Dictionary<string, object>
                {
                    { "value", "Hello world!" }
                };

                await host.StartAsync();
                await jobHost.CallAsync("CreateQueueMessage", inputs);
                await host.StopAsync();
            }
        }
    }
}

As an additional note, I did find a similar issue posted on SO: Azure Functions - can't be invoked from Azure WebJobs SDK

However, changing the target framework (to .netstandard) isn't in any part of the Microsoft docs. And I would find it odd that the docs would direct me to specifically create a .net console azure web jobs app, only to change it to .netstandard later. And, just for kicks, I did try that solution, but it produced an entirely different error:

The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.

So I think this other post is a different issue.

Matt Spinks
  • 5,382
  • 1
  • 18
  • 39
  • That linked issue was because the OP had created the function using .net platform rather than .net core, hence the need to change target framework to .net standard. – Ben Jun 17 '19 at 02:25
  • I figured it was something like that. At the very least, I don't want this to be marked as a possible duplicate. It does seem to be a different issue. – Matt Spinks Jun 17 '19 at 02:34

1 Answers1

2

Just change class Program to public class Program then you would work well.

The whole code looks like below:

public class Program
{
    [NoAutomaticTrigger]
    public static void CreateQueueMessage(ILogger logger, string value, [Queue("myqueue")] out string message)
    {
        ...
    }
    public static void Main(string[] args)
    {
        ...
        ...
    }
}
Joey Cai
  • 15,590
  • 1
  • 7
  • 19
  • 1
    Yep, that was it. I'm a little embarrassed now. That should have been obvious. It makes sense. `jobHost.CallAsync("CreateQueueMessage", inputs)` will call `CreateQueueMessage` in a different scope. Thanks for the help. – Matt Spinks Jun 17 '19 at 20:29