Skip to content

Templates and resources for F# Http Trigger function broken #1096

Open

Description

Where to start...

I've been trying for a full day to create a Azure function using F# and I've finally managed to do so after following many tutorials (outdated or up to date, but with bugs) and applying changes from a couple of not merged PRs and issues on different repositories.

Following this official page it is unclear what tutorial I need to follow, but after trial and error I have found out that they are all outdated.

After landing on this page I thought that finally I have landed on a single page where I have all the information I need to get started, but no there is not a single useful thing on that page to get started.

Then I started searching on the Internet for F# azure function tutorials and I landed on this page which pointed me in the direction of azure template for F# functions. Up until this point I have not heard or read anything about these templates. Upon further research I realized that that article was just a copy from this page from @aaronpowell.

Then I added the templates:

dotnet new --install Microsoft.Azure.WebJobs.ItemTemplates
dotnet new --install Microsoft.Azure.WebJobs.ProjectTemplates

Then I run this command:

dotnet new func -lang F# -o FunctionsInFSharp 

Output:

The template "Azure Functions" was created successfully.

An update for template pack Microsoft.Azure.WebJobs.ProjectTemplates::3.1.1812 is available.
    install command: dotnet new -i Microsoft.Azure.WebJobs.ProjectTemplates::4.0.1844-preview1

Then I run this command to add a http trigger function:

dotnet new http -lang F# --name HttpTrigger -o FunctionsInFSharp 

Output:

The template "HttpTrigger" was created successfully.

Processing post-creation actions...
Description: Opens the function class file in the editor
Manual instructions:


An update for template pack Microsoft.Azure.WebJobs.ItemTemplates::3.1.1812 is available.
    install command: dotnet new -i Microsoft.Azure.WebJobs.ItemTemplates::4.0.1844-preview1

Again, do I need to update or not? No clue.

Then I opened the directory with VSCode and the extension (Azure Functions) displayed this message:

Detected an Azure Functions Project in folder "fsharp-azure-functions" that may have been created outside of VS Code. Initialize for optimal use with VS Code?

I clicked yes, and I got a new directory .vscode with some files inside. It adds the tasks for:

  • build
  • func host start
  • clean
  • clean release
  • publish

They all work, except the publish command. I have no clue what does that do.

Then I press F5 and get this message:

Failed to verify "AzureWebJobsStorage" connection specified in "local.settings.json". Is the local emulator installed and running?

I click on "Debug anyway". (This popup keeps showing everytime I hit F5.)

Then I get these two messages:

[2021-09-14T20:51:43.340Z] Csproj not found in /home/mabasic/code/src/github.com/laravelista/fsharp-azure-functions/FunctionsInFSharp/bin/Debug/netcoreapp3.1 directory tree. Skipping user secrets file configuration.

and

[2021-09-14T20:51:45.660Z] 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.).

I fix the second message with this step which is mentioned in the blog post.

I included the file HttpTrigger.fs in FunctionsInFSharp/FunctionsInFSharp.fsproj as mentioned in the blog post in:

<ItemGroup>
<Compile Include="HttpTrigger.fs" />
</ItemGroup>

and pressed F5 to debug the function as instructed.

Then I got this error:

Host.json file in missing. Please make sure host.json file is present at /home/mabasic/code/src/github.com/laravelista/fsharp-azure-functions/FunctionsInFSharp/bin/Debug/netcoreapp3.1

I fix this by changing this line in FunctionsInFSharp.fsproj file:

<None Update="host.json">

to

<None Include="host.json">

and

<None Update="local.settings.json">

to

<None Include="local.settings.json">

Once again I hit F5. This time I get a warning, but the function starts correctly:

[2021-09-14T20:56:13.010Z] Csproj not found in /home/mabasic/code/src/github.com/laravelista/fsharp-azure-functions/FunctionsInFSharp/bin/Debug/netcoreapp3.1 directory tree. Skipping user secrets file configuration.

Functions:

        HttpTrigger: [GET,POST] http://localhost:7071/api/HttpTrigger

The deployment worked and it seemed that all is good, but then I noticed that it is targeting netcoreapp3.1. I wanted to use net5.0, so I change this line in FunctionsInFSharp.fsproj from

<TargetFramework>netcoreapp3.1</TargetFramework>

to

<TargetFramework>net5.0</TargetFramework>

Then I run dotnet restore and run "Task clean" and "Task clean release". After that the function builds correctly but after I deploy it (I select .NET 5 as the runtime) I get this error:

The remote runtime "dotnet-isolated" for function app "test-sample-net5" does not match your local runtime "dotnet".

Then I change this line in local.settings.json from:

"FUNCTIONS_WORKER_RUNTIME": "dotnet"

to

"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"

and then I delete the directories bin and obj and run "Task build" and "Task func host start" and then I get:

> Executing task: dotnet build /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary <

Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  FunctionsInFSharp -> /home/mabasic/code/src/github.com/laravelista/fsharp-azure-functions/FunctionsInFSharp/bin/Debug/net5.0/FunctionsInFSharp.dll

Terminal will be reused by tasks, press any key to close it.

> Executing task: func host start <

it stalls and does nothing.

Then I've learned about .NET isolated process (in-process and out-of-process) here. It would seem that using dotnet-isolated is required to use net5.0 runtime.

After checking the issues and pull requests I have found this:

After a few hours of tweaking things and experimenting with packages, code, and configuration I've succeeded to create a working function which uses net5.0 under dotnet-isolated runtime.

I am willing to create a PR or a starter repository for this if needed.

Can we somehow streamline this whole experience so that I can pick if I want to use net5.0 or netcoreapp3.1 and that it works correctly without me having to read issues and PR code and other people example repositories for a simple bootstrap command to work?

Do I need to add a new template for this or are going in the func new direction?

My impression now is that considering how broken this whole experience feels like, I am not sure if proceeding with F# Azure functions is a way to go for now. I got the function to work, but my next step is using CosmosDB and I am afraid of what I will find next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions