azure-function-dependency-injection icon indicating copy to clipboard operation
azure-function-dependency-injection copied to clipboard

Not working with Microsoft.Extensions.DependencyInjection v2.2.0

Open AlexPiksel opened this issue 6 years ago • 6 comments

This may be a duplicate of #21, although that doesn't capture the impact.

We've just updated our project to .NET Core 2.2 / EF Core 2.2, which means the datalayer class library our Functions project references now has a dependency on Microsoft.Extensions.DependencyInjection >= 2.2.0

This causes the following error on startup:

[17/12/2018 14:51:49] A host error has occurred
[17/12/2018 14:51:49] Willezone.Azure.WebJobs.Extensions.DependencyInjection: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.WebJobs.IWebJobsBuilder.get_Services()'.
Value cannot be null.
Parameter name: provider

This prevents the function from starting.

If I downgrade the data layer back to 2.1.x libraries, the error goes away. If I then add an explicit reference to Microsoft.Extensions.DependencyInjection v2.2.0 to the functions project, it comes back, so it looks like this is the culprit.

For reference, both the Function project and the class library it's referencing are netstandard2.0. My local functions runtime is 2.0.12210.0, while Azure is running 2.0.12246.0 - same issue seen in both.

AlexPiksel avatar Dec 17 '18 15:12 AlexPiksel

Having had a bit of a dig through, I don't think this can be done until Microsoft.Azure.WebJobs.Host is also upgraded to 2.2

We ran into the issue, but not after an upgrade - we were creating an entirely new project and had, as such, added a dependency on Microsoft.Extensions.Options version 2.2.0 to add IOptions<T> to DI.

We observed the error reported above, but also

A host error has occurred
[20/12/2018 16:45:02] Willezone.Azure.WebJobs.Extensions.DependencyInjection: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.WebJobs.IWebJobsBuilder.get_Services()'.

Ensuring that all ASP.NET Core references were pegged at 2.1.1 has resolved it for us for now.

DarranShepherd avatar Dec 20 '18 16:12 DarranShepherd

@BorisWilhelms

Maybe an out-of-the-box question : why not create a source-code only NuGet package ? In that way you don't need to upgrade the NuGet everytime Microsoft releases a new version from a library,

StefH avatar Dec 20 '18 17:12 StefH

@StefH,

Maybe an out-of-the-box question : why not create a source-code only NuGet package ? In that way you don't need to upgrade the NuGet everytime Microsoft releases a new version from a library,

Yes, that is probably the right approach since AF is so picky with common dependencies. I use that for our internal utilities in v1. Unfortunately it doesn't work in v2 because the runtime only picks up extensions in external dependencies and fix is not a priority Azure/Azure-Functions#972

adrianm64 avatar Dec 23 '18 17:12 adrianm64

It sounds like it's a priority!

https://github.com/Azure/Azure-Functions/issues/972#issuecomment-444973009

SeriousM avatar Dec 23 '18 20:12 SeriousM

@adrianm64 Another option would be to more active manage this project + nuget. And keep the same version scheme as from Microsoft.

So make multiple versions from Willezone.Azure.WebJobs.Extensions.DependencyInjection which align with Microsoft.Azure.WebJobs:

  • 2.1.0
  • 2.2.0
  • 3.0.0
  • 3.0.1
  • 3.0.3

StefH avatar Dec 28 '18 13:12 StefH

For those running into this issue, I found I was able to get past it by updating my Azure Functions Runtime that ships with VS for Mac to latest as of this posting

Azure Functions Core Tools (2.7.1575 Commit hash: b7750e771a4e56352c767dfa16413ec9c79b72ba)
Function Runtime Version: 2.0.12625.0

This SO post pointed me in the right direction: https://stackoverflow.com/questions/55377996/net-core-2-2-azure-function-v2-dependency-injection

kensykora avatar Aug 21 '19 17:08 kensykora