.netcore Azure functions startup class is not called

Viewed 2080

My Azure function doesn't calls the startup class localy. When running the project, my brekpoint doesn't hit the DependencyRegistrations.Register function.

Package Microsoft.Azure.Functions.Extensions is correctly installed

using Microsoft.Azure.Functions.Extensions.DependencyInjection;

[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]

namespace MyNamespace
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            DependencyRegistrations.Register(builder.Services);
        }
    }
}

enter image description here

Why is the startup class not called?

2 Answers

Two things I'm not seeing in your code snippet.

1- [assembly: FunctionsStartup(typeof(MyNamespace.Startup))]

2- Are you sure the nuget package was properly installed? (Microsoft.Azure.Functions.Extensions)

The final startup code should look like the following:

using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]

namespace MyNamespace
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddHttpClient();

            builder.Services.AddSingleton<IMyService>((s) => {
                return new MyService();
            });

            builder.Services.AddSingleton<ILoggerProvider, MyLoggerProvider>();
        }
    }
}

I face the same issue, i have to remove my project from my solution and recreate an new to have the statup to be called...

I suspect a version mistake somewhere

Related