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://learn.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.
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)
{
...
...
}
}