Reputation: 105
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>
Upvotes: 0
Views: 1647
Reputation:
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.
Upvotes: 1