Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templated QueueTrigger name fails to resolve in 3.0.3. #2063

Open
panesofglass opened this issue Dec 19, 2018 · 8 comments
Open

Templated QueueTrigger name fails to resolve in 3.0.3. #2063

panesofglass opened this issue Dec 19, 2018 · 8 comments

Comments

@panesofglass
Copy link

panesofglass commented Dec 19, 2018

Defining a [QueueTrigger("%InputQueue%")] fails to resolve the InputQueue from the App.config appSettings.

Repro steps

Provide the steps required to reproduce the problem

  1. Add an App.config setting in appSettings for InputQueue, e.g. <add key="InputQueue" value="queue" />

  2. Set the QueueTriggerAttribute to use the templated value, e.g. [QueueTrigger("%InputQueue%")]

Expected behavior

Prior to 3.0.*, the queue trigger would pick up the queue name from the App.config appSettings.

Actual behavior

Runtime exception:

Unhandled Exception: Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method 'Functions.processQueueMessage' ---> System.InvalidOperationException: '%InputQueue%' does not resolve to a value.
   at Microsoft.Azure.WebJobs.Host.NameResolverExtensions.ResolveWholeStringCore(INameResolver resolver, String resolve, Boolean throwOnFailure) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\NameResolverExtensions.cs:line 99
   at Microsoft.Azure.WebJobs.Host.NameResolverExtensions.ResolveWholeString(INameResolver resolver, String resolve) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\NameResolverExtensions.cs:line 36
   at Microsoft.Azure.WebJobs.Host.Queues.Triggers.QueueTriggerAttributeBindingProvider.Resolve(String queueName) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Queues\Triggers\QueueTriggerAttributeBindingProvider.cs:line 99
   at Microsoft.Azure.WebJobs.Host.Queues.Triggers.QueueTriggerAttributeBindingProvider.TryCreateAsync(TriggerBindingProviderContext context) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Queues\Triggers\QueueTriggerAttributeBindingProvider.cs:line 61
   at Microsoft.Azure.WebJobs.Host.Triggers.CompositeTriggerBindingProvider.TryCreateAsync(TriggerBindingProviderContext context) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Triggers\CompositeTriggerBindingProvider.cs:line 22
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsyncCore(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 190
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 167
   --- End of inner exception stack trace ---
   at Microsoft.Azure.WebJobs.Host.RecoverableException.TryRecover(ILogger logger) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Exceptions\RecoverableException.cs:line 83
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexTypeAsync(Type type, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 112
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexProvider.CreateAsync(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexProvider.cs:line 79
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexProvider.GetAsync(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexProvider.cs:line 64
   at Microsoft.Azure.WebJobs.Host.Executors.JobHostContextFactory.Create(CancellationToken shutdownToken, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\JobHostContextFactory.cs:line 101
   at Microsoft.Azure.WebJobs.JobHost.InitializeHostAsync(CancellationToken cancellationToken, TaskCompletionSource`1 initializationTask) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs:line 359
   at Microsoft.Azure.WebJobs.JobHost.StartAsyncCore(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs:line 99
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at WebJobExample.Program.main(String[] argv) in C:\Code\fsharp-azure-webjob\WebJobExample\Program.fs:line 19

Known workarounds

None.

Related information

@panesofglass
Copy link
Author

panesofglass commented Dec 19, 2018

Seems this is undocumented. I was able to fix it by adding a singleton service:

let configNameResolver =
    { new INameResolver with
        member __.Resolve(name) =
            ConfigurationManager.AppSettings.[name] }

[<EntryPoint>]
let main argv =
    let builder =
        HostBuilder()...
            .ConfigureServices(fun services ->
                // This seems to correctly add the name resolver for the QueueTrigger
                services.AddSingleton(configNameResolver) |> ignore
            )
            // rest of configuration
    use host = builder.Build()
    host.Run()
    0

@ranouf
Copy link

ranouf commented Aug 20, 2019

Hi, I have the same error.

@panesofglass could you give more details about your fix, I dont know how to implement it, it does not seem to be C#.

Thanks :)

@panesofglass
Copy link
Author

panesofglass commented Aug 20, 2019

@ranouf, the above is F#. For C#, the following should work:

class ConfigNameResolver : INameResolver
{
    public string Resolve(string name)
    {
        return ConfigurationManager.AppSettings[name];
    }
}

class Program
{
    public static void Main(string[] args)
    {
        var configNameResolver = new ConfigNameResolver();
        var builder =
            new HostBuilder()
                .ConfigureServices(services =>
                    // This seems to correctly add the name resolver for the QueueTrigger
                    services.AddSingleton(configNameResolver);
                );
        using (var host = builder.Build())
        {
            host.Run();
        }
    }
}

@ranouf
Copy link

ranouf commented Aug 20, 2019

Thanks, it works!

@MirzaMerdovic
Copy link

Thanks @panesofglass I can confirm that I have this same issue when trying to run Azure Durable Function in Linux Container and I had to do the same workaround.
Although my INameResolver implementation is the same as the DeafaultNameResolver in Azure WebJobs, but I had to include the "Values" prefix in order to retrieve the value _configuration[$"Values:{name}"], of course this implies that the values are under AppSettings.Values inside appsettings.json.

@pragnagopa
Copy link
Member

@fabiocav / @brettsam - FYI

@mdurini
Copy link

mdurini commented May 4, 2021

We faced the same issue. We tried to publish the azure function app from Visual Studio 2019 version 16.9.4 and we discovered that the application setting that we configured in the "Manage Azure app service settings" were ignored if the setting was "classname:propertyname" (example "Idp:Cloud")
This problem is not happening with settings without the class name (example "IsScopeMonitored")
We didn't tried to configure the settings directly from the azure portal.

@textbytext
Copy link

Hello.
The problem is in the FunctionIndexProvider.cs file.

FunctionIndexer indexer = new FunctionIndexer(_triggerBindingProvider, 
...
_instanceServicesFactory, 
null, 
_sharedQueue, 
...
_defaultRetryStrategy); 

The INameResolver does not passing (null instead) to the constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants