question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FunctionIndexingException thrown when same function method name is used in different classes

See original GitHub issue

Having a [ServiceBusTrigger] attribute Message parameter on one or methods with the same name, but in different classes, throws Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method System.ArgumentException: An item with the same key has already been added. in FunctionIndexer.cs line 93 when the webjob console app starts.

It appears this broke from version 3.0.22 as 3.0.19 still works OK.

Repro steps

  1. Create a Webjob console application and reference version >= 3.0.22.

  2. Create two classes MessageOneHandler and MessageTwoHandler.

  3. Add methods to each class with the same name and containing a ServiceBusTrigger attribute parameter: HandleMessage([ServiceBusTrigger(...)] Message message) {...}

  4. Run the console application

Expected behavior

No exception is thrown and both methods are invoked for the service bus topic / queue they are configured to use.

Actual behavior

Exception above is thrown:

Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method System.ArgumentException: An item with the same key has already been added. in FunctionIndexer.cs line 93:

   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 98
   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 95
   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 69
   at Microsoft.Azure.WebJobs.Host.Executors.JobHostContextFactory.Create(JobHost host, CancellationToken shutdownToken, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\JobHostContextFactory.cs:line 108
   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 347
   at Microsoft.Azure.WebJobs.JobHost.StartAsyncCore(CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs:line 97
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at StudyTravel.File.ServiceBus.Subscribers.Program.Main() in /home/dan/projects/StudyTravel/File/src/StudyTravel.File.ServiceBus.Subscribers/Program.cs:line 51
   at StudyTravel.File.ServiceBus.Subscribers.Program.<Main>()

Known workarounds

Use a unique name per method even if in different classes e.g.

public class MessageOneHandler
{
    public async Task HandleMessageOne([ServiceBusTrigger(...) Message message) {...}
}

public class MessageTwoHandler
{
    public async Task HandleMessageTwo([ServiceBusTrigger(...) Message message) {...}
}

Related information

It appears the changes in FunctionIndexer.cs in this commit are the cause of the breaking change:

https://github.com/Azure/azure-webjobs-sdk/pull/2556/commits/76d44ca915b817ed3f3cc46e355aa6cb0f741b4b

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fabiocavcommented, Mar 22, 2021

The packages have been deployed. thank you for the patience!

1reaction
fabiocavcommented, Mar 3, 2021

Assingning this to myself to update when deployed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do I see a FunctionIndexingException when creating ...
It means the SAS string you got is not authorized correctly even if SDK doesn't require blob access. You could ask partner team...
Read more >
Solving Azure Functions - "cannot find function:" with Event ...
I have been trying to automate the provisioning and deployments of Azure Functions using ARM Templates & PowerShell scripts for quite some ...
Read more >
[Solved]-WebJob throws FunctionIndexingException with ...
The WebJob cannot setup multiple methods that share a name (overloads). Rename the methods so that they are not overloads: public static class...
Read more >
Microsoft.Azure.WebJobs.Host: Error indexing method
When adding a queueTrigger in my project i get this error The 'AutoAssign' function is in error: Microsoft.Azure.WebJobs.
Read more >
Connect Azure Functions to Azure Storage using Visual ...
Learn how to connect Azure Functions to an Azure Queue Storage by adding an output binding to your Visual Studio Code project.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found