44

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"
}
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86

22 Answers22

38

If you are using Azure Functions in .NET 5 or higher 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")]
Thom
  • 663
  • 7
  • 19
  • 1
    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 Jun 26 '21 at 22:04
  • 1
    Here's the official documentation: https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-developer-howtos?tabs=browser&pivots=development-environment-vs#rename-the-function – Magnus Johansson Jun 26 '21 at 22:12
  • 2
    God damn you saved me hours of madness, thanks! – Spaceman Jun 27 '21 at 11:42
  • 1
    Why would they change this? – Wouter Nov 09 '21 at 13:18
  • 6
    What is the Nuget package and the namespace for the FunctionAttribute? – Bassem Aug 30 '22 at 18:42
  • `Function` attribute is in the namespace `Microsoft.Azure.Functions.Worker` – Amr Eladawy Sep 25 '22 at 22:53
  • 2
    I think the reason this response may have been downvoted is because it is easy to miss the "out-of-proces execution model" reference, and the error message in the original post doesn't indicate in or out of process. To clarify: [Function] is for out of process and [FunctionName] is the attribute for in process. I got here because I was looking up the error message in an in-process upgrade to v4 from v3 on Azure recommendation and had this error message when in-process. In this case, the [Function] attribute is a red herring. – David Bridge Nov 23 '22 at 15:25
  • @DavidBridge Did you find a solution to your problem? I am also receiving this error while trying to upgrade the function runtime from 3 to 4 on an in-process function. – Quiver Nov 28 '22 at 21:45
  • 2
    The complete lack of quality in the Function project creation process using latest VS 2022 is unbelievable. Azure Functions team, is anyone there paying attention? – Dagrooms Feb 07 '23 at 20:39
  • No clear documentation, all the ones from Microsoft are outdated. No nice sample or template found in internet for Azure Webjobs! – Sharif Yazdian Jun 17 '23 at 16:30
  • You are transforming WebJob to an Isolated Azure Function (Worker Role) https://stackoverflow.com/questions/25825290/worker-role-vs-web-job – Sharif Yazdian Jun 17 '23 at 17:16
  • Thanks mate, this worked for me on .NET 6 and function version 4 – Ryan James Jul 27 '23 at 21:36
21

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

MarkD
  • 1,511
  • 18
  • 32
12

I randomly had this issue but it only affected the functions in one class. Turned out I just needed to run a dotnet clean first.

Dan N
  • 121
  • 1
  • 4
7

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!

Gerard
  • 2,832
  • 3
  • 27
  • 39
6

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.

Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86
Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
6

My issue was different from the other answers: the local.settings.json was explicitly included in the .gitignore definition. As such the file was not included in a clone and the local build couldn't understand which was the correct runtime to use.

I pulled the default local.settings.json from a sample project to restore the file.

Superman.Lopez
  • 1,332
  • 2
  • 11
  • 38
1

In my case (v3 on net core 3.1) it was a weird case that somehow this was removed from csproj file.

<None Update="local.settings.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  <CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
Leszek P
  • 1,807
  • 17
  • 24
1

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.

Lozzer
  • 155
  • 2
  • 12
1

I got the error mentioned in the question in Rider when I tried to run localy azure function. I tried to run proejct in Visual Studio and I got another error during the build:

A project with an Output Type of Class Library can not be started directly.

It turned out that I removed at some point from csproj package reference:

<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />

After adding it to csproj I am able to run azure function.

Jaryn
  • 446
  • 4
  • 16
1

I had this issue after I changed the project from .Net Core to .Net 6.0 Framework.
In the end I created a new project from scratch and copied the code across.

GreenRock
  • 111
  • 6
1

so for me it worked when i startet the function with: "func start --csharp"

edit: after the first time starting the function with the func start --csharp command i can now start it normal with func start

c m
  • 11
  • 2
0

I appreciate the other answers here. But in my case none of them worked on VS Code.

I am still trying to use .NET core SDK version of 2.1 and had to use all old version of dependencies for my Azure function.

Even after everything seeming right, I was still unable to run the function locally. Turns out, there is a small step to be taken:

  1. First, publish your project dotnet publish

  2. The published stuff should be in bin/Debug/netstandard2.0 . Just get inside this folder and run your function:

    cd bin/Debug/netstandard2.0  # I was using netstandard2.0 framework
    func start --build # You can add --verbose flag for more detailed outputs
    

Voila! That's it. Just to be clear, here are my versions:

  • .NET core SDK version: 2.1.810
  • Azure CLI version: 2.12.0
  • Azure Function version: v2
  • Microsoft.NET.Sdk.Functions: 1.0.37
Furqan Rahamath
  • 2,034
  • 1
  • 19
  • 29
0

in my scenario, for Existing Project, I missed to give reference in .csproj file after installing azure function setup in windows

here is it

you can run command on VS Code Func init --force and Select Dotnet template and then delete .csproj file which is created automatically.

local.settings.json

"Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=false",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }

.csproj file

<ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
  </ItemGroup>  

I hope someone helps out there if you are using like me visual studio code.

saurav singh
  • 438
  • 6
  • 16
0

It happened to me when I changed the name of the project and some other refactoring. It was working on that machine after the change, but interesting enough when I switch to a different machine, I got this error - even if it's the same code.

The solution was for me basically creating a random new azure function and running again. All my functions appeared on the cli on the next run.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mehmet Taha Meral
  • 3,315
  • 28
  • 30
0

I was running "func start" from the wrong folder. Make sure you're running it from the root folder of the azure function. This should be true for any language (I'm using python)

Jeffrey Kozik
  • 201
  • 4
  • 8
0

I found this error when I use FunctionName like this:

 [FunctionName("Example/signup")]

I removed "/" in FunctionName and resolved it.

0

After having upgraded a lot of packages - amongst others the one that triggered the change from [FunctionName("CreateData")] to [Function("CreateData")], I needed to delete the bin and obj folder before the functions were discovered again.

Stig Stavik
  • 75
  • 1
  • 8
0

Had this error on my local machine out of the blue, after nuget update of an shared assembly. The same function still worked on a build server. It looks like something lingering from past build outputs/packages caused this.

My Setup:

  • .NET 7, out of process.
  • VS.NET 2022
  • Core Tools Version: 4.0.5085 Commit hash: N/A (32-bit)
  • Function Runtime Version: 4.16.4.20366

I had to do the following to get rid of the issue:

  • Stop VS.NET
  • Delete bin folders
  • Delete obj folders
  • Clear nuget cache in C:\Users<username>.nuget
  • Restart VS.NET, build and run
Gopal Krishnan
  • 968
  • 11
  • 14
0

I got this error during cleanup, when I recreated my project from an existing project. I had originally left out the host.json file. But I continued to see the message when launching the core tools window.

I deleted the bin and obj folders in the project folder, restarted and this seemed to fix the problem.

John
  • 59
  • 4
-1

If it's working from bin/Debug/netcoreapp3.1/ etc this is because you are missing some needed files in the root or missing sections in some files. (eg: host.json)

I managed to fix this by running func init --force to restore the initial setup and use git to find the missing sections.

enter image description here

Chris Gunawardena
  • 6,246
  • 1
  • 29
  • 45
-1

I got the error

no job functions found

when my firewall was blocking the azure functions program from connecting to the internet.

JensB
  • 6,663
  • 2
  • 55
  • 94
-2

For some reason, my working project got this below info duplicated in the csproj file, and so ran into this same error while running the AzFunction locally. I removed the extraneous lines and it worked just fine.

<ItemGroup>
    <None Include="Function1.cs" />
</ItemGroup>
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Anand Sowmithiran
  • 2,591
  • 2
  • 10
  • 22