Azure Functions v3 dependency injection issue

adriana_malea 141 Reputation points
2021-10-04T13:27:02.81+00:00

Hello,

When trying to use DI with [FromServices], it fails with the following build error:

Error Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
...................
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()
Error generating functions metadata

I have used:

Microsoft.NET.Sdk.Functions" Version="3.0.13" and "Microsoft.Azure.Functions.Extensions" Version="1.1.0".

Looks like a few people have bumped into that one: https://stackoverflow.com/questions/64185565/failed-to-resolve-assembly-microsoft-aspnetcore-mvc-core-version-3-1-0-0-when, but there is no official workaround for this.

I haven't seen any response/solution from Microsoft. Is there an incompatibility between libs, what is the combination that I should use?
If this method injection doesn't work, can you please tell me what other alternatives do I have?

Thank you!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
0 comments No comments
{count} votes

Accepted answer
  1. Pramod Valavala 20,656 Reputation points Microsoft Employee Moderator
    2021-10-05T09:58:45.003+00:00

    @adriana_malea The attribute you are trying to use for ASP.NET Core MVC Controllers. They are not applicable for Azure Functions and removing it should help like mentioned in the answer of the SO post you shared.

    While Azure Functions does inject certain dependencies (like ILogger) into functions, custom services are only injected into class constructors. The Dependency Injection for .NET Functions doc covers the supported scenarios.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.