9

I have just created a new Azure Functions project with a Queue Trigger, straight out of the box using the following tech stack, and it doesn't build, and returns an error stating that " Error CS1061: 'HostBuilder' does not contain a definition for 'ConfigureFunctionsWebApplication'".

Tech Stack

  • Visual Studio for Mac (17.6.8).
  • .Net 7.0
  • Azure Functions v4

Here is the code where the error occurs (straight out of the box Program.cs file)

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication() //FAILING ON THIS LINE HERE!
    .ConfigureServices(services => {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

host.Run();

Here is the QueueTrigger (straight out of the box):

using System;
using Azure.Storage.Queues.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace AzureFunctionsDotNet7Example
{
    public class QueueTriggerFunctionExample
    {
        private readonly ILogger<QueueTriggerFunctionExample> _logger;

        public QueueTriggerFunctionExample(ILogger<QueueTriggerFunctionExample> logger)
        {
            _logger = logger;
        }

        [Function(nameof(QueueTriggerFunctionExample))]
        public void Run([QueueTrigger("myqueue-items", Connection = "connection-string-goes-here")] QueueMessage message)
        {
            _logger.LogInformation($"C# Queue trigger function processed: {message.MessageText}");
        }
    }
}

Here is the .csproj file for the project, for reference:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.3.0" />
    <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>

I came across this post here on StackOverflow, however this did not fix the issue (Installing NuGet Package Microsoft.AspNetCore.Hosting).

Any ideas on how to fix this? Help greatly appreciated. Many thanks.

UPDATE 1: Here is the repository on Github

UPDATE 2: Following on from the answered provided by Pravallika KV, I added all of the required missing NuGet Packages, which did indeed fix the build, but the application now fails with the following error:

"Failed to load /Users/Library/Application Support/VisualStudio/azure-functions-cli/Releases/4.67.0/cli_arm64/libhostpolicy.dylib, error: dlopen(/Users/Library/Application Support/VisualStudio/azure-functions-cli/Releases/4.67.0/cli_arm64/libhostpolicy.dylib, 0x0001): tried: '/Users/Library/Application Support/VisualStudio/azure-functions-cli/Releases/4.67.0/cli_arm64/libhostpolicy.dylib' (mach-o file, but is an incompatible architecture (have'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/Library/Application Support/VisualStudio/azure-functions-cli/Releases/4.67.0/cli_arm64/libhostpolicy.dylib' (no such file), '/Users/Library/Application Support/VisualStudio/azure-functions-cli/Releases/4.67.0/cli_arm64/libhostpolicy.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')) An error occurred while loading required library libhostpolicy.dylib from [/Users/Library/Application Support/VisualStudio/azure-functions-cli/Releases/4.67.0/cli_arm64/]"

4
  • Install these packages Azure.Storage.Blobs,Azure.Storage.Files.Shares,Azure.Storage.Queues,Microsoft.Azure.Functions.Worker.Extensions.Http,Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore,Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues,Microsoft.Extensions.Azure. Refer Image. Commented Feb 7, 2024 at 13:41
  • Thanks, they've all worked except "Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" which has an error - "Error CS0234: The type or namespace name 'Storage' does not exist in the namespace 'Microsoft.Azure.Functions.Worker.Extensions' (are you missing an assembly reference?" Commented Feb 7, 2024 at 13:52
  • Try upgrading or downgrading Microsoft.Azure.Functions.Worker.Extensions package version. Commented Feb 7, 2024 at 14:10
  • 3
    It seems the project template on Visual Studio on Mac is missing Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore as a dependency. Adding this Nuget package resolved the error above. Commented Mar 28, 2024 at 11:03

3 Answers 3

13

What worked for me was adding the following package...

Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore
Sign up to request clarification or add additional context in comments.

1 Comment

same here. but for some reason, it added a lower version of the package (even though I did not specify the version when I did dotnet add). I had to do a package update and then, the error went away.
3

You need to install the missing NuGet packages.

  • I have created a .NET 7 isolated Queue triggered Azure function.

.Csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.13.1" />
    <PackageReference Include="Azure.Storage.Files.Shares" Version="12.1.0" />
    <PackageReference Include="Azure.Storage.Queues" Version="12.11.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
    <PackageReference Include="Microsoft.Extensions.Azure" Version="1.5.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>

Function.cs:

using System;
using Azure.Storage.Queues.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
 
public class Function
 {
     private readonly ILogger<Function1> _logger;

     public Function1(ILogger<Function1> logger)
     {
         _logger = logger;
     }

     [Function(nameof(Function))]
     public void Run([QueueTrigger("myqueue-items", Connection = "demo")] QueueMessage message)
     {
         _logger.LogInformation($"C# Queue trigger function processed: {message.MessageText}");
     }
 }

Program.cs:

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

host.Run();

local.settings.json:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "<storage_connection_string>",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
    }
}

host.json:

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            },
            "enableLiveMetricsFilters": true
        }
    }
}

Console Output:

[2024-02-07T15:43:01.514Z] Azure Functions .NET Worker (PID: 28100) initialized in debug mode. Waiting for debugger to attach...
[2024-02-07T15:43:01.738Z] Worker process started and initialized.

Functions:

        Function1: queueTrigger

For detailed output, run func with --verbose flag.
[2024-02-07T15:43:07.583Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
[2024-02-07T15:43:08.845Z] Executing 'Functions.Function1' (Reason='New queue message detected on 'myqueue-items'.', Id=8be1eaf6-f837-44d1-ae01-42777355955e)
[2024-02-07T15:43:08.853Z] Trigger Details: MessageId: e0a9f004-ab4d-4ae7-a01a-a0c4c6c0040f, DequeueCount: 1, InsertedOn: 2024-02-07T15:43:08.000+00:00
[2024-02-07T15:43:09.233Z] C# Queue trigger function processed: Hello World
[2024-02-07T15:43:09.335Z] Executed 'Functions.Function1' (Succeeded, Id=8be1eaf6-f837-44d1-ae01-42777355955e, Duration=656ms)

3 Comments

I'm now getting a different error. I've updated my question with the full error, thanks!
Check for updates in visual Studio and try rebuilding the project.
I'm running the latest version of everything, but I'm on a MacBook Pro with a silicon chip (although I believe this is now supported). Thanks for your help
2

My PC has the following .NET SDKs installed:

8.0.202 [C:\Program Files\dotnet\sdk]

8.0.400 [C:\Program Files\dotnet\sdk]

Replace ConfigureFunctionsWebApplication() with  ConfigureFunctionsWorkerDefaults()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.