Michael Edenfield
Michael Edenfield

Reputation: 28338

Where is the "Startup Code" in an Azure Fuctions project?

I'm trying to write an Azure Function that uses the ServiceBus bindings as a trigger. I've upgraded everything to netstandard 2.0 and the pre-release v3.0 versions of the WebJobs packages, so I have everything building correctly and generating the metadata etc.

When I try to run the project, the Azure Functions host starts up but complains that I have no functions defined, and suggests I might have to configure custom bindings manually in the startup code. I also get a null reference error related to the function I'm trying to deploy, which I suspect may also be caused by the unknown trigger binding attribute.

I know that the Service Bus bindings are not built in anymore, and need to be registered, but I have no idea where I'm supposed to do this. My project is just a class library, it has no "startup code".

This is what I get when I start up the project:

[1/5/2018 4:15:46 PM] A function whitelist has been specified, excluding all but the following functions: [ProcessCheckRecognition, ImageConversion]
[1/5/2018 4:15:47 PM] Generating 0 job function(s)
[1/5/2018 4:15:47 PM] Starting Host (HostId=9f4ea53c5136457d883d685e57164f08, Version=2.0.11353.0, ProcessId=12424, Debug=False, Attempt=0, FunctionsExtensionVersion=)
Listening on http://localhost:7071/
Hit CTRL-C to exit...
[1/5/2018 4:15:47 PM] No job functions found. Try making your job classes and methods public. 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.).
[1/5/2018 4:15:47 PM] Job host started
[1/5/2018 4:15:47 PM] The following 1 functions are in error:
[1/5/2018 4:15:47 PM] ProcessCheckRecognition: Object reference not set to an instance of an object.

Here's my function class:

public static class JobResponse
{
    [FunctionName("ProcessJobResponse")]
    public static void Run([ServiceBusTrigger("ktl-jobresponse")]ResponseMessage message, TraceWriter log)
    {
    }
}

And the function.json that is generated on build:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.7",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "serviceBusTrigger",
      "queueName": "ktl-jobresponse",
      "name": "message"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/KutuluWare.Functions.dll",
  "entryPoint": "KutuluWare.Functions.JobResponse.Run"
}

Am I supposed to be calling config.UseServiceBus() somewhere, and if so, where is that code expected to live?

Upvotes: 2

Views: 1336

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35144

Run func command and make sure you are using v2 tools (currently in beta):

enter image description here

You can install those by running npm install -g azure-functions-core-tools@core

See also this answer to a similar problem.

Upvotes: 3

Related Questions