No job functions found. Try making your job classes and methods public

34,550

Solution 1

Another gotcha I found especially if you are converting from another project or version.

In the VS csproj file, make sure AzureFunctionsVersion is present

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
...etc

the tooling adds this automatically but not added if you are modifying a project where this was missing. Hope this helps you save the 3 hours it cost me :-).

Solution 2

If you are using Azure Functions in .NET 5 with the out-of-proces execution model you need to replace your FunctionName with Function, otherwise the function will not be detected.

Before:

[FunctionName("CreateData")]

After:

[Function("CreateData")]

Solution 3

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 the 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.

Solution 4

In my case I was simply running the command from an actual function directory. You should run it from the root of the functions project instead!

Solution 5

In my case, the clue was this message at the start of the console output:

Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell]

Adding the --csharp argument did the trick.

Share:
34,550

Related videos on Youtube

Murray Foxcroft
Author by

Murray Foxcroft

Pop over to LinkedIn or Code Project to get to know more about me.

Updated on July 09, 2022

Comments

  • Murray Foxcroft
    Murray Foxcroft almost 2 years

    First off, I have looked at the other SO posts with the same error message and none seem to resolve my issue. I have tried many permutations and options. My function builds fine but will not run in the CLI, I get the following cryptic error. The MSFT documentation does not seem to have the answers either.

    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.).

    I am trying to run a timer job and then write a collection of messages to an event hub. What am I missing? I have been fighting this for hours.

    Function:

        [FunctionName("CreateData")]
        public static async Task Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
            [EventHub("murraytest", Connection = "evingest")] IAsyncCollector<string> myeventhub,
            TraceWriter log)
        {
            await myeventhub.AddAsync("data1");
            await myeventhub.AddAsync("data2");
            await myeventhub.AddAsync("data3");
    
            log.Info($"COMPLETED: {DateTime.Now}");
        }
    

    local.settings.json:

    {
      "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "Eventhub": "UseDevelopmentStorage=true",
        "AzureWebJobsDashboard": "",
        "evingest": "Endpoint=sb://example.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=LtcqBLT5VWjg0dGMdIvxCcEGs8902010Y6y14iGg="
    
      }
    }
    

    Packages

    Nuget

    function.json - is missing any eventhub bindings!

    {
      "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
      "configurationSource": "attributes",
      "bindings": [
        {
          "type": "timerTrigger",
          "schedule": "0 */5 * * * *",
          "useMonitor": true,
          "runOnStartup": false,
          "name": "myTimer"
        }
      ],
      "disabled": false,
      "scriptFile": "..\\bin\\AzFuncs.dll",
      "entryPoint": "AzFuncs.Function1.Run"
    }
    
    • Mikhail Shilkov
      Mikhail Shilkov over 6 years
      Do you mind upgrading to the latest Sdk.Functions (1.0.6)?
    • Mikhail Shilkov
      Mikhail Shilkov over 6 years
      First remove ServiceBus reference, then upgrade Sdk, then add it again
    • Mikhail Shilkov
      Mikhail Shilkov over 6 years
      ServiceBus should be 2.1.0-beta4 too
    • Mikhail Shilkov
      Mikhail Shilkov over 6 years
      When you are done, check that function.json file is generated in bin\Debug\net461\CreateData
    • Murray Foxcroft
      Murray Foxcroft over 6 years
      Ok, fixing the assemblies to the correct versions in a new project worked for this error, but I do notice that the functions.json built in the bin is missing eventhub bindings. The function now runs, but no messages produced.
    • Mikhail Shilkov
      Mikhail Shilkov over 6 years
      It's ok, input and output bindings are not put into generated json file. They still work.
  • Magnus Johansson
    Magnus Johansson almost 3 years
    Thanks, this is indeed the correct answer if one is using .NET 5! Upvoted (I fail to understand why someone down voted this answer, I upvoted)
  • Magnus Johansson
    Magnus Johansson almost 3 years
    Here's the official documentation: docs.microsoft.com/en-us/azure/azure-functions/…
  • Spaceman
    Spaceman almost 3 years
    God damn you saved me hours of madness, thanks!
  • Wouter
    Wouter over 2 years
    Why would they change this?
  • eyal
    eyal over 2 years
    Thanks! That thing was holding me back too.
  • Superman.Lopez
    Superman.Lopez over 2 years
    @eyal glad it was helpful. Feel free to upvote my answer! :)