Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
419 stars 182 forks source link

No job functions found running an F# function #364

Open recumbent opened 3 years ago

recumbent commented 3 years ago

If I take the templated C# function, port the project to F# and attempt func start

I get:

Azure Functions Core Tools
Core Tools Version:       3.0.3388 Commit hash: fb42a4e0b7fdc85fbd0bcfc8d743ff7d509122ae
Function Runtime Version: 3.0.15371.0

[2021-03-23T09:53:46.162Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
For detailed output, run func with --verbose flag.
[2021-03-23T09:53:51.196Z] Host lock lease acquired by instance ID '000000000000000000000000BD321FD0'.

I'm hoping that I just missed something obvious, but at this point its not clear what that might be.

The ported code is as below

HttpExample.fs:


namespace fsharp_isolated

open System.Collections.Generic;
open System.Net;
open Microsoft.Azure.Functions.Worker;
open Microsoft.Azure.Functions.Worker.Http;
open Microsoft.Extensions.Logging;

module HttpExample =

   [<Function("HttpExample")>]
   let Run ([<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")>] req : HttpRequestData , executionContext : FunctionContext ) : HttpResponseData =
        let logger = executionContext.GetLogger("HttpExample")
        logger.LogInformation("F# HTTP trigger function processed a request.")

        let response = req.CreateResponse(HttpStatusCode.OK)
        response.Headers.Add("Content-Type", "text/plain; charset=utf-8")

        response.WriteString("Welcome to Azure Functions!")

Program.fs:

namespace fsharp_isolated

open System.Threading.Tasks;
open Microsoft.Extensions.Configuration;
open Microsoft.Extensions.Hosting;
open Microsoft.Azure.Functions.Worker.Configuration;

module Program =
    [<EntryPoint>]
    let main _ =
        let hostBuilder = new HostBuilder()
        hostBuilder.ConfigureFunctionsWorkerDefaults() |> ignore

        let host = hostBuilder.Build()
        host.Run()

        0

The full project is here: https://github.com/recumbent/fsharp-isolated

recumbent commented 3 years ago

Further to the above, @marklam found that if one makes the changes below to the .fsproj then it will find the function and work with func start

i.e. change Update to Include in both cases

fabiocav commented 3 years ago

@recumbent thank you for the update.

We'll be working on some F# templates, so hopefully that will address those types of issues.

/cc @anthonychu