Open coreConvention opened 5 years ago
I think this question belongs in the WebJobs SDK repo. @fabiocav would you mind transferring it over and taking a look? The GitHub issue transfer feature isn't allowing me to do so myself (it's not visible to me).
@cgillum if you think thats where it needs to go great. However, I have only observed this behavior using durable functions. Everything seems to work as expected with the regular azure functions. shrugs
Anyhow, thanks for taking a look nonetheless!
I was able to get this sorted out. Turns out this fails when referencing any 2.2.0 versions of the Microsoft.Extensions.Configuration packages. Going back to 2.1.0 seems to fix the issue. Although even after that I had more issues with Microsoft.Extensions.Logging, because of a dependency on Microsoft.Extensions.DependecyInjection.Abstractions. In the end all of those related packages had to be downgraded to 2.1.0.
Adding on to say - it looks like this happens with any package in the Microsoft.Extensions namespace. I started encountering a similar issue when adding the Microsoft.Extensions.Caching.Memory 2.2.0 package.
@cgillum I am using version 3.1.0 of Microsoft.Extension and still getting the same issue, it seems that the configuration builder does have some crazy behavior with durable function. Given below is the code I am using, is there a workaround for this?
private static AppSettings GetApplicationSettings()
{
var configBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appSettings.json", optional: true, reloadOnChange: true).AddEnvironmentVariables().Build();
var appSettings = new AppSettings();
configBuilder.GetSection("AppSettings").Bind(appSettings);
return appSettings;
}
This seems like such an odd error, and it may not be a bug. But was hindering something I was trying to do with IServicesCollection so I was hoping someone might know whats going on. I am attempting to use a ServiceBusTrigger with a Durable function. I am using an implementation of IWebJobsStartup to do my registrations. I had originally approached this the same way I do with normal functions; I instantiate an instance of ConfigurationBuilder in the configure method of my IWebJobsStartup implementation and pass my config instance to a function where I register all my services.
One registration in particular requires the ConfigurationBuilder to resolve connection string through an instance of IConfiguration:
This worked great with normal functions but a couple weird things happen with durable functions. The first was an error:
Which oddly enough seemed to happen even if I wasn't using the instance of configurationbuilder anywhere. Its very existance seems to cause this error. Even just having "var config = new ConfigurationBuilder().Build();" in there but not using it would cause this error. Deleting it resolves that issue. Weird. This happens when it calls builder.AddServiceBus(p => { }) in ServiceBusWebJobsBuilderExtensions.cs in the service bus extensions. The stack trace is at the bottom of this issue.
I remove the var config = new ConfigurationBuilder()...Build(); stuff from IWebJobsStartup it just magically starts working. Again this happens whether I use "config" or not.
So anyway I removed that assuming maybe it was interfering with something in the service bus extensions, and tried to just resolve IConfiguration from the service provider in my registration:
...at which point I get an error saying it could not resolve IConfiguration. Doh! So I just removed the connection string from the constructor in ContextProvider and attempted to resolve IConfiguration instead, but it seems I cannot resolve IConfiguration from anywhere in the app either, even when the rest of it is working. Am I missing something here? How can I use IConfiguration in durable functions with IConfiguration?