F# class in Azure isolated process function. No job functions found

Tri Nguyen 0 Reputation points
2024-08-02T20:02:30.16+00:00

I could not create an Azure isolated process function if I use F# class semantics, it works with the native F# function semantic. Could someone please take a look? Thank you!

The error is: No job functions found. Try making your job classes and methods public. If you're using binding extensions [...more...]

`module Functions`

open Domain

open Microsoft.Azure.Functions.Worker

open Microsoft.Extensions.Configuration

open Microsoft.Extensions.Logging

// this works, but could not use dependency registered in Host

[<Function("TimerTriggerFunction")>]

let TimeIntervalFunction ([<TimerTrigger("*/10 * * * * *")>] myTimer: TimerInfo) (context: FunctionContext) =

let logger = context.GetLogger("functionlogger")

logger.LogInformation("function is triggered!")

// I need dependency injection but this doesn't work

type public TimeIntervalFunctionClass() =

[<Function("TimerTriggerFunctionInClass")>]

member _.Run ([<TimerTrigger("*/5 * * * * *")>] myTimer: TimerInfo) (context: FunctionContext) =

let logger = context.GetLogger("classlogger")

logger.LogInformation("timer trigger in class")

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,110 questions
F#
F#
A strongly typed, multi-paradigm programming language developed by the F# Software Foundation, Microsoft, and open contributors.
71 questions
.NET F#
.NET F#
.NET: Microsoft Technologies based on the .NET software framework.F#: A strongly typed, multi-paradigm programming language developed by the F# Software Foundation, Microsoft, and open contributors.
106 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pinaki Ghatak 4,610 Reputation points Microsoft Employee
    2024-08-08T19:58:45.9833333+00:00

    Hello @Tri Nguyen

    The error message you mentioned here suggests that you should make your job classes and methods public. In your code, you have defined a public class TimeIntervalFunctionClass, but the Run method is not public.

    You should make the Run method public so that it can be discovered by the Azure Functions runtime. Here's an updated version of your code with the Run method made public:

    module Functions
    
    open Domain
    
    open Microsoft.Azure.Functions.Worker
    
    open Microsoft.Extensions.Configuration
    
    open Microsoft.Extensions.Logging
    
    // I need dependency injection but this doesn't work
    
    type public TimeIntervalFunctionClass() = [] member public _.Run ([] myTimer: TimerInfo) (context: FunctionContext) =
    
    let logger = context.GetLogger(classlogger)
    
    logger.LogInformation("timer trigger in class")
    

    Note that I also added quotes around the log message in the Run method.


    I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.