Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.94k stars 442 forks source link

"function runtime is unable to start" when trying to add Mvc Core #5205

Open bragma opened 5 years ago

bragma commented 5 years ago

Hi, I am trying to use Razor Engine as a templating engine in a V2 function. I have it running locally, but not when deployed as a function. When selecting the function name from the portal, it gives "The function runtime is unable to start."

I've managed to strip everything down to a sample function with bare code and tried a lot of combinations with the basic initialization code, but not resolved.

Investigative information

Please provide the following:

Repro steps

I've built a sample HttpTrigger function from VS2019 template, and just added this:

[assembly: FunctionsStartup(typeof(TestFunction.Startup))]
namespace TestFunction
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            ConfigureServices(builder.Services);
        }

        private void ConfigureServices(IServiceCollection services)
        {
            // This line causes error in runtime
            services.AddMvcCore();
        }
    }
}

I also tried with a more complex startup adding logging etc. but it gives the same error on the "AddMvcCore" line. If I comment that line, it works.

Actual behavior

Function does not run. Runtime does not start. Navigating to the function name tab in the portal shows a "function runtime is unable to start" error.

Related information

Provide any related information

bragma commented 5 years ago

As an addenda, here is the minimal sample code:

https://github.com/bragma/TestFunction/tree/master/TestFunction

brettsam commented 5 years ago

We already call AddMvc() -- have you tried your solution without that? I believe all the services registered by AddMvcCore() should already be registered.

bragma commented 5 years ago

We already call AddMvc() -- have you tried your solution without that? I believe all the services registered by AddMvcCore() should already be registered.

Do you mean that IFunctionsHostBuilder already has Mvc in its services and there is no need to do it again? Even for functions with queue trigger?

Is there a list of default services?

Thanks a lot!

brettsam commented 5 years ago

We don't have a list of default services anywhere -- but it's a good idea. The Web host that runs the Functions host adds MVC (it has admin controllers that run, for example, even if you don't have an HttpTrigger). If you're able to get running, I can repurpose this issue to tackle the doc update.

mhoeger commented 4 years ago

@brettsam - moving this to triaged and adding "docs" tag