Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in Azure Function App VS 2019 .NET 3.0 - Method not found: 'IFunctionsHostBuilder.get_Services()'

Issue with Azure Functions/EFSQLSERVER .NET CORE 3.0:

To reproduce:

  • Use Visual Studio 2019 16.2.1
  • Use Azure Function template to create a project.
  • Changed Target Framework to .NET Core 3.0
  • Add Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" reference via Nuget Package Manager.
  • Excecut Function App using F5

Results in an error as showing in the following snippets. Anyone came across this issue?

Azure Functions Core Tools (2.7.1633 Commit hash: 45c7d86a3bbc9ed0a80a8f4199aa7ea80ccfb24e)
Function Runtime Version: 2.0.12673.0
[10/4/2019 6:13:14 PM] Building host: startup suppressed:False, configuration suppressed: False
[10/4/2019 6:13:14 PM] Loading startup extension 'Startup'
[10/4/2019 6:13:14 PM] Loaded extension 'Startup' (1.0.0.0)
[10/4/2019 6:13:14 PM] Loading startup extension 'DurableTask'
[10/4/2019 6:13:14 PM] Loaded extension 'DurableTask' (1.0.0.0)
[10/4/2019 6:13:14 PM] A host error has occurred
[10/4/2019 6:13:14 PM] FunctionApp5: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.
Value cannot be null.
Parameter name: provider

My nuget packages from csproj file.

<ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.8.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
  </ItemGroup>
using Microsoft.Azure.Functions.Extensions.DependencyInjection;


[assembly: FunctionsStartup(typeof(FunctionApp5.Startup))]
namespace FunctionApp5
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            **var x = builder.Services;**

        }
    }
}

.NET Core 3.0

enter image description here

like image 847
Athadu Avatar asked Oct 04 '19 18:10

Athadu


People also ask

What is dependency injection in Azure?

Azure Functions supports the dependency injection (DI) software design pattern, which is a technique to achieve Inversion of Control (IoC) between classes and their dependencies. Dependency injection in Azure Functions is built on the . NET Core Dependency Injection features.


3 Answers

This saved my day

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
like image 161
Paul Sorensen Avatar answered Oct 21 '22 02:10

Paul Sorensen


For now,ASP.NET Core 3.0 not currently available for Azure App Service, check this Microsoft doc.

Azure Functions 3.0, which will be fully compatible with Core 3.0, will be available in October, check here. However it's not released now.

From this issue, you could find Azure Function 2.0 right now does not work with any Microsoft.Extensions.* 3.* packages and cannot share code with .Net Core 3.0 services.

Further more information about Azure Fuction 3.0 check this discussion.

like image 3
George Chen Avatar answered Oct 21 '22 00:10

George Chen


You can now use .net core 3.0 to create azure functions. Update Microsoft.NET.Sdk.Functions to 1.0.30-beta2 and set AzureFunctionsVersion to v3-preview.

Read more about Develop Azure Functions using .NET Core 3.0 here

enter image description here

You can now use DI using IFunctionsHostBuilder

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

[assembly: FunctionsStartup(typeof(BI_Geo.AzureFunctions.Startup))]
namespace BI_Geo.AzureFunctions
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddScoped<IProcess, Process>();
        }
    }
}
like image 3
sjokkogutten Avatar answered Oct 21 '22 01:10

sjokkogutten