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

5

11

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

Cenis answered 4/10, 2019 at 18:25 Comment(1)
This must be package issues as I have a similar problem. Just by adding the http extensions package (Microsoft.Http.Extensions) I get this error (without using any code from that package). By removing it, the error goes away. I am on 16.3.2 with the same webjobs version.Bassoon
B
3

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.

Brutal answered 7/10, 2019 at 9:14 Comment(2)
Got it. Thank you.Cenis
Rumor has it that the publish preview will be available by Oct. 25thSapotaceous
S
3

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>();
        }
    }
}
Sapotaceous answered 21/10, 2019 at 11:7 Comment(1)
This worked for me - in case the above fix is not working and the function project uses nuget Microsoft.EntityFrameworkCore 3.1.0, downgrade to 3.0.1 otherwise there will be the same errorBlab
P
1

This saved my day

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
Purslane answered 16/7, 2020 at 10:26 Comment(0)
C
1

To add something else to look out for, the following was our issue:

  • Our functions app referenced a Domain project
  • Our Domain project referenced "Microsoft.Extensions.Localization version 5.0.1, which in turn referenced a 5.x version of Microsoft.Extensions.DependencyInjection, which was incompatible with our 3.x runtime. Once we downgraded to reference Microsoft.Extensions.Localization version 3.1.10, the Microsoft.Extensions.DependencyInjection reference downgraded with it and everything worked.
Charentemaritime answered 23/12, 2020 at 15:54 Comment(2)
Took me an age to unravel this, but essentially no v5.x dependancies are compatible with .Net Core 3. These are .Net 5 runtimes. Annoyingly Nuget doesn't seem to care what version your targeting and offers to upgrade assemblies to v5 even if they'll break your buildCory
I'm attempting to get Nuget to address this issueCory
C
-1

Until Azure Functions 3.0 is available as a stable release, the easiest seems to be to downgrade the Microsoft.Extensions.Http package to 2.2.0:

It helped me with the same problem as there seems to be no other workaround in place for now. Even the available beta packages aren't working on a build server.

enter image description here

More details here: Azure functions dependency injection - error when referencing class library (Github).

Culley answered 21/11, 2019 at 21:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.