azure-function-dependency-injection
azure-function-dependency-injection copied to clipboard
Not working with Microsoft.Extensions.DependencyInjection v2.2.0
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.
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.
@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,
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
It sounds like it's a priority!
https://github.com/Azure/Azure-Functions/issues/972#issuecomment-444973009
@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
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