0

I have migrated some Azure Functions from .NET Core 2.2 to 3.1 and implemented the dependency injections for my function's class and I am getting this error:

Executed 'GetDataAsync' (Failed, Id=1f90c913-4385-4ef9-9f40-09e413191ba9, Duration=222ms)
[2022-03-30T19:43:43.143Z] Microsoft.Azure.WebJobs.Script.WebHost:
Registered factory delegate returns service is not assignable to ambiently scoped container with {no name, Parent={no name}}.
[2022-03-30T19:43:43.268Z] An unhandled host error has occurred.
[2022-03-30T19:43:43.272Z] Microsoft.Azure.WebJobs.Script.WebHost: Registered factory delegate returns service is not assignable to ambiently scoped container with {no name, Parent={no name}}.

 <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Common1" Version="1.0.33.3" />
    <PackageReference Include="Common2" Version="3.12.0.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.6.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.23" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.23" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="3.1.23" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.23" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.23" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" />
  </ItemGroup>
4
  • 3
    there isn't enough info here. can we see how you're registering your services? Also, have you made sure your packages are also upgraded? Could you provide more code. Commented Mar 31, 2022 at 5:06
  • Could you provide .csproj code and the function code written the DI to check the appropriate versions of NuGet Packages and Code suitable when migrating from 2.2 to 3. Commented Mar 31, 2022 at 6:11
  • Does this help? Commented Mar 31, 2022 at 11:36
  • I have just shared .csproj file. @Steven, I have tried that link. It is not working. Commented Mar 31, 2022 at 12:44

1 Answer 1

1

Please check if the below steps help to:

As following this medium article, I resolved the same error when adding the dependency injections to one of the Azure Functions Project v3 migrated from .NET 2.2:

The error I got:

Microsoft.Azure.WebJobs.Script.WebHost: Registered factory delegate returns service Microsoft.Extensions.Logging.LoggerFactory is not assignable to container. Value cannot be null. (Parameter 'provider')

In Startup.cs File, registered the Serilog logger in the builder.Services.AddLogging method and Serilog Logger is created with its own instance and all the configurations.

// Startup.cs - Registering a third party logging provider
var logger = new LoggerConfiguration()
                .WriteTo.Console()
                .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
                .CreateLogger();
builder.Services.AddLogging(lb => lb.AddSerilog(logger));

Also, please refer this Microsoft Documentation helps you regarding the usage of Dependency Injection in .NET Azure Functions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.