example does not work
uranio-235 opened this issue · 2 comments
I came here from
https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection
The related example does not work with the following error:
Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection
Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.
The error looks like this
[10/3/2020 19:15:45] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: 'a86e9ee9-9a4c-4960-9ad9-9cb89b1266f6'
[10/3/2020 19:15:45] Reading host configuration file 'C:\Users\lazaro\source\repos\WealFunction\WealFunction\bin\Debug\netcoreapp2.1\host.json'
[10/3/2020 19:15:45] Host configuration file read:
[10/3/2020 19:15:45] {
[10/3/2020 19:15:45] "version": "2.0"
[10/3/2020 19:15:45] }
[10/3/2020 19:15:45] Reading functions metadata
[10/3/2020 19:15:45] 1 functions found
[10/3/2020 19:15:45] Loading startup extension 'Startup'
[10/3/2020 19:15:45] Loaded extension 'Startup' (1.0.0.0)
[10/3/2020 19:15:45] A host error has occurred during startup operation 'a86e9ee9-9a4c-4960-9ad9-9cb89b1266f6'.
[10/3/2020 19:15:45] WealFunction: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.
This is my startup
using System;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WealFunction.Abstract;
using WealFunction.Data;
using WealFunction.Models.Entities;
// Fix this error:
// Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection
// Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.
[assembly: FunctionsStartup(typeof(WealFunction.Startup))]
namespace WealFunction
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddTransient<User>();
}
} // class
}
An this is the related funcion:
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using WealFunction.Abstract;
using WealFunction.Data;
using WealFunction.Models;
using WealFunction.Models.Entities;
namespace WealFunction.Functions
{
public class AnnualInterestRate
{
private readonly IRepository<User> _userIdal;
public AnnualInterestRate(IRepository<User> userIdal)
{
_userIdal = userIdal;
}
[FunctionName("AnnualInterestRate")]
public void Run([TimerTrigger("0 30 11 * * *", RunOnStartup = true)]TimerInfo myTimer)
{
return;
} // Run
} // class
}
I following the same instructions and I got the error:
Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. O sistema não pode encontrar o arquivo especificado.
Value cannot be null. (Parameter 'provider')
Nothing can solve it.
Sorry for the delayed response, we must have missed this issue. Are you still seeing the same problem with all the latest packages?
If you're still seeing this issue:
I cloned the sample and it ran for me without issues: https://github.com/Azure/azure-functions-dotnet-extensions/tree/main/src/samples/DependencyInjection/Scopes
Can you share a minimal repro project for me to investigate? It's likely something is setup different to how the above sample does things.