1

I have a Function App in azure and when I hit the URL of the function app it says "Function host is not running." I have checked the log also in the app insights or in the Azure portal's function app service, it shows the following error message in the function app.

Note: My pipeline's Build & Releases got succeeded, so I am not sure where to check and what is the solution for this. I tried with a new function app but still no luck.

enter image description here

My Startup.cs file to understand How I have referred the config values,

 public override void Configure(IFunctionsHostBuilder builder)
    {
        //var connectionString = Environment.GetEnvironmentVariable("ConnectionStrings:DBConnection");

        var serviceProvider = builder.Services.BuildServiceProvider();
        _configuration = serviceProvider.GetRequiredService<IConfiguration>();
        var appSettingsSection = _configuration.GetSection("AppSettings");
        builder.Services.Configure<AppSettings>(appSettingsSection);
        var appSettings = appSettingsSection.Get<AppSettings>();
        RuntimeConfig.appsettings = appSettings;

        var ConnectionString = RuntimeConfig.appsettings.AppDBConnection;
        ///builder.Services.AddDbContext<ShardingDbContext>(options => options.UseSqlServer(ConnectionString), ServiceLifetime.Transient);
        //builder.Services.AddScoped<ITestService, TestService>();


    }

    public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
    {
        FunctionsHostBuilderContext context = builder.GetContext();

        builder.ConfigurationBuilder
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, "local.settings.json"), optional: true, reloadOnChange: false)
            .AddJsonFile(Path.Combine(context.ApplicationRootPath, $"{context.EnvironmentName}.settings.json"), optional: true, reloadOnChange: false)
            .AddEnvironmentVariables();
    }

I am taking the config values as IConfiguration, it works for my local but don't know how to do the same in the server.

Md Aslam
  • 1,228
  • 8
  • 27
  • 61
  • Do you use something with the name "EIA"? – Markus Meyer Jun 07 '22 at 08:20
  • are you missing some app settings ? – Thomas Jun 07 '22 at 08:51
  • @MarkusMeyer Yes, How do you know that? – Md Aslam Jun 07 '22 at 11:25
  • @Thomas I think yes but I don't know how to add that – Md Aslam Jun 07 '22 at 11:26
  • @MdAslam That's in the error message. "EIA: Object reference not set to an instance of an object". so, this EAI needs some configuration (code or app settings). I guess this configuration is wrong or missing – Markus Meyer Jun 07 '22 at 11:30
  • @MarkusMeyer ahh yeah but how to add my local.settings.json file to the kudu path? I have added it but when I run it again then the build files are getting vanished so I don't know how to make it available in the release bin folder in the azure function app server.. Can you please help me? – Md Aslam Jun 07 '22 at 11:37
  • local settings will not be deployed. You have to configure it in the app: https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings?tabs=portal#settings – Markus Meyer Jun 07 '22 at 11:43
  • you can check this link to configure app settings for azure function: https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings?tabs=portal#settings – Thomas Jun 07 '22 at 11:43

1 Answers1

1

while deploying your Function app it neither upload local.settings.json to Azure or nor makes modification on Application Settings based on local.settings.json file.

The Key-value pair related to EIA present in local.settings.json, add the same key-value pair in Azure Function App Configuration > Application Settings in the Portal.

For that we have to manually update the App Settings in portal or if you are using Visual studio, we can update using VS publish panel.

Add Application Settings using Portal

  • Azure Portal -> Your Azure Function -> Configuration Panel -> Application Settings/Connection Strings (Add your custom configuration) enter image description here

Add Application Settings using Visual Studio Publish panel

  • While publishing your azure function Add your Application settings.

  • In a hosting panel right corner click (...).

  • Add your app Settings in Manage Azure App Service Settings. enter image description here

  • Add your settings like below enter image description here

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15
  • Actually my json values are very simple and that does not contain any key name EIA, I have like => "AppSettings": { "AppDBConnection": "xyz db connection string;", } – Md Aslam Jun 08 '22 at 05:09
  • I tried with adding these json config values in the configurations as well but the error remain same. – Md Aslam Jun 08 '22 at 05:10
  • if you are adding the DB connection settings try to add in a connection strings under the Application Settings panel. Like [this](https://i.imgur.com/8Y9La4d.png) – Delliganesh Sevanesan Jun 08 '22 at 05:13
  • I have edited my questions with statup.cs file code so please check and let me know what would be the solution, I understood the problem as you mentioned but it does not work even after created the configurations-application settings as well – Md Aslam Jun 08 '22 at 05:14
  • 1
    you can use **`Environment.GetEnvironmentVariable($"ConnectionStrings:{}")`** to get the exact connection string value. – Delliganesh Sevanesan Jun 08 '22 at 05:27
  • So I should not use the IConfiguration then ? – Md Aslam Jun 08 '22 at 06:19
  • You can use any one of approach. Refer [here](https://stackoverflow.com/a/51784441/15997690). And also you can use Iconfiguration . Refer [here](https://stackoverflow.com/questions/59959258/how-to-add-an-appsettings-json-file-to-my-azure-function-3-0-configuration) – Delliganesh Sevanesan Jun 08 '22 at 07:51