When porting an application that uses a settings file to an Azure Function, is it necessary to remove reliance on the file?
I want to write a function app to import data from Xero into an Azure sql database. The Xero SDK I am using is expecting an appsettings.json file.
Consequently when the function runs I get the error
System.Private.CoreLib: Exception while executing function:
FunctionXeroSync. Xero.Api: The type initializer for
'Xero.Api.Infrastructure.Applications.Private.Core' threw an exception.
Microsoft.Extensions.Configuration.FileExtensions: The configuration file
'appsettings.json' was not found and is not optional. The physical path is
'C:\Users\kirst\AppData\Local\AzureFunctionsTools\Releases\2.6.0\cli\appsettings.json'.
I tried putting the relevant settings in via the Manage Application Settings link on the VS2017 Project Publish Tab. Clearly this fails. Is there another way I can use?
Here is the relevant code in the api. I would prefer not to have to modify it, so that I can use the official nuget package.
namespace Xero.Api
{
public class XeroApiSettings : IXeroApiSettings
{
public IConfigurationSection ApiSettings { get; set; }
public XeroApiSettings(string settingspath)
{
var builder = new ConfigurationBuilder()
.AddJsonFile(settingspath)
.Build();
ApiSettings = builder.GetSection("XeroApi");
}
public XeroApiSettings() : this("appsettings.json")
{
}
public string BaseUrl => ApiSettings["BaseUrl"];
public string CallbackUrl => ApiSettings["CallbackUrl"];
public string ConsumerKey => ApiSettings["ConsumerKey"];
public string ConsumerSecret => ApiSettings["ConsumerSecret"];
public string SigningCertificatePath => ApiSettings["SigningCertPath"];
public string SigningCertificatePassword => ApiSettings["SigningCertPassword"];
public string AppType => ApiSettings["AppType"];
public bool IsPartnerApp => AppType?.Equals("partner", StringComparison.OrdinalIgnoreCase) ?? false;
}
}
When I add
log.LogInformation("base directory: "+AppDomain.CurrentDomain.BaseDirectory);
to the function I get
D:\Program Files (x86)\SiteExtensions\Functions\2.0.12095-alpha\32bit\
when running in the portal