9

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

Kristoffer Jälén
  • 3,223
  • 3
  • 21
  • 39
Athadu
  • 646
  • 6
  • 9
  • 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. – MarkD Oct 05 '19 at 20:24

5 Answers5

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.

George Chen
  • 11,105
  • 2
  • 6
  • 20
2

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>();
        }
    }
}
sjokkogutten
  • 1,666
  • 2
  • 18
  • 20
  • 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 error – Felice Anno Dec 03 '19 at 16:26
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.
NSouth
  • 4,477
  • 7
  • 38
  • 71
  • 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 build – Liam Jan 14 '21 at 11:26
  • I'm attempting to get [Nuget to address this issue](https://github.com/NuGet/Home/issues/10455) – Liam Jan 14 '21 at 11:36
0

This saved my day

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
Paul Sorensen
  • 407
  • 2
  • 6
  • 13
-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).

Quality Catalyst
  • 5,693
  • 7
  • 34
  • 57