Azure-webjobs-sdk: FunctionIndexingException thrown when same function method name is used in different classes

Created on 27 Nov 2020  路  6Comments  路  Source: Azure/azure-webjobs-sdk

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.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 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, TaskCompletionSource1 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.

()

#### 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

All 6 comments

Thanks for reporting. Fix will go out in the next package update.

@mathewc Could you keep this issue open until it is fixed?

Or perhaps could you post an update here when that is released? I have the same issue :)

Yes, when the new package version is on nuget, I'll let you know.

I think release has been made, but nuget package has not been deployed to nuget.org

Assingning this to myself to update when deployed.

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

Was this page helpful?
0 / 5 - 0 ratings