Skip to content

FunctionsStartup not being called after runtime update in Azure, causing DI failure #5401

Closed
@hallidev

Description

@hallidev

I had recently updated my Azure Functions from v3-preview to v3 after the .NET Core 3.1 GA announcement. Everything was running fine for development locally and in Azure.

At almost exactly 10:30PM EST on Friday (2019-12-13), all of my functions in development and production environments (two different resource groups) started failing.

Everything still runs fine locally.

The reason is that FunctionsStartup is no longer being run. I have no means by which to fix this as these functions were developed from day 1 in .NET Core 3 and have netcoreapp3.1 dependencies I can't change. I have no way to rollback these functions to v2.

My functions app on Azure reads:
Runtime version: 3.0.12939.0 (~3)

Local development reads:
Azure Functions Core Tools (3.0.2009 Commit hash: 77395527a4e9c28da8400dcfd1a450f4e0d0c36c)
Function Runtime Version: 3.0.12930.0

Let me reiterate - this was working after upgrading from v3-preview to v3. It stopped working after something was deployed by the Azure team

This is incredibly frustrating as a breaking changed was simply introduced by someone at Microsoft.

Investigative information

Please provide the following:

  • Timestamp: 2019-12-16T20:08:06.480
  • Function App version (1.0 or 2.0): 3.0.12939.0
  • Function App name: CavFunctions-Dev
  • Function name(s) (as appropriate): all functions
  • Invocation ID:
  • Region: East US

Repro steps

Register something in a DI Container like so:

[assembly: FunctionsStartup(typeof(MyApp.Functions.Startup))]
namespace MyApp.Functions
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            // Register things in DI container
            builder.Services.AddScoped<Greeter>();
        }
    }
}

Use it like so:

    public class MyFunction
    {
        private readonly Greeter _greeter;

        public MyFunction(Greeter greeter)
        {
            _greeter = greeter
        }

        // Every 5 minutes
        [FunctionName(nameof(MyFunction))]
        public async Task Run([TimerTrigger("0 0/5 * * * *", RunOnStartup = true)]TimerInfo myTimer, CancellationToken cancellationToken)
        {
            await _greeter.Greet();
        }
    }

Expected behavior

Constructor injection works properly

Actual behavior

FunctionsStartup ignored, Greeter isn't registered in DI container, results in exception:

Unable to resolve service for type 'Greeter' while attempting to activate 'MyApp.MyFunction'. System.InvalidOperationException: at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService (Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at lambda_method (Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)

Known workarounds

#5401 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions