Event Hub Trigger not working in .Net Core
I have a function with a EventHubTrigger in Visual Studio 2017 :
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.ServiceBus;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([EventHubTrigger("myEventHub", Connection = "myConnection")]string myEventHubMessage, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myEventHubMessage}");
}
}
}
I have this error :
[10/01/2018 16:55:13] The following 1 functions are in error: [10/01/2018 16:55:13] Function1: Unable to configure binding 'myEventHubMessage' of type 'eventHubTrigger'. This may indicate invalid function.json properties. Can't figure out which ctor to call.
After investigating, I figured out that Visual Studio generates a wrong function.json :
{
"generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.7",
"configurationSource": "attributes",
"bindings": [
{
"type": "eventHubTrigger",
"path": "myeventhub",
"connection": "myConnection",
"name": "myEventHubMessage"
}
],
"disabled": false,
"scriptFile": "../bin/FunctionApp1.dll",
"entryPoint": "FunctionApp1.Function1.Run"
}
There is no direction element. Could it be the cause of the error ?
The issue is likely that in .NET core the Event Hub trigger is actually no longer a part of Microsoft.Azure.WebJobs.ServiceBus. This reflects the Service Bus team pulling it out as a separate SDK..
The fact that it's not throwing an error at build is strange but see if replacing with this package resolves your issues. If so I'll open a bug to throw an error if not using this package in .net core:
https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.EventHubs
The problem is the wrong property name in the functions.json file. -> "path" instead of "eventhubname" With the example above, if you manually change the file to have: "path": "myeventhub", "eventhubname": "myeventhub", works for me.
@DamiaoCastro ... How does that work at deployment time? I was able to get around this issue with your suggested fix, but I'm concerned about when we actually want to move this into production.
@bellyhold , the application builds fine, but when the application starts and begins to "read" all the functions, the error "Can't figure out which ctor to call." shows up. By changing the property name in the function.json file from "path" to "eventhubname" the application doesn't have that error anymore. The property name in the EventHubTriggerAttribute is "EventHubName", not path.
https://github.com/Azure/azure-webjobs-sdk/blob/dev/src/Microsoft.Azure.WebJobs.ServiceBus/EventHubs/EventHubTriggerAttribute.cs#L28
@DamiaoCastro , Sorry if I'm not asking the right questions. I'm new to Azure Functions... but a little more context...
We have a Jenkins build server that does a clean and build on deploy. Based on my local testing I'm assuming that the Jenkins clean and build will overwrite the manual edit (path => eventhubname) and cause everything to fail again after deploy. Do you know if there is a fix for this in the works?
Sorry @bellyhold , I'm in no way involved in the development of the azure functions sdk nor extensions. I assume that the problem resides here: https://github.com/Azure/azure-webjobs-sdk-templates/blob/dev/Functions.Templates/Bindings/bindings.json#L90
But I'm not sure at all.
Maybe @jeffhollan can better answer your question.
@DamiaoCastro, should we open an issue in the azure-webjobs-sdk-templates instead ?
I don't know what should happen anymore. In the documentation, I see this:

(https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs#trigger---configuration) So the script versions of eventHub implementations work already like that...
So, I decided to issue a pull request on the "EventHubTriggerAttribute".
https://github.com/Azure/azure-webjobs-sdk/pull/1551
Because the error is inside "AttributeCloner.CreateDirect" the is a internal class in a very different part of the project, I was not able to UnitTest it. In my computer, I copied the AttributeCloner class to the EventHub project and I saw the code run correctly. Also had problems with my nuget build of the "Microsoft.Azure.WebJobs.Extensions.EventHubs" package, so I was not able to make it run in a standalone project.
Honestly it seems like a hack that the parameter names of the attribute constructor even matter. A seemingly innocuous refactor could break things.
@jeffhollan any updates on this? Seems like a barrier to cleanly utilizing this library for eventhub/iot hub.
@jeffhollan Also really interested in seeing this issue get resolved. Was trying to demo an IoT solution to a friend to get them familar with Azure and was sad to see that I'm unable to use functions to connect to EventHub in this current state
@WonderPanda it works, it's just annoying because you have to go into the bin and manually edit the generated functions.json file
@onionhammer That's not working, there's clearly a bug that needs to be fixed here. I'm fine to change it for myself but the point is that these things need to be more seamless. If I'm doing a talk inside my company about building IoT apps using Azure services I don't want to have to demo the need to go in and mess with files manually in the bin folder
@onionhammer, I totally agree with @WonderPanda : it is not suitable in industry solution to have to manually change a file for making the solutions works.
@WonderPanda @EhRom not arguing that this is a huge annoyance and it needs to be resolve ASAP.. hint hint microsoft.. I was saying that the functionality of consuming an EH via an azure function does indeed work, just that the generation of function.json is broken.
+1 please resolve - not usable in CI / CD like this
Even if I manually modify the attribute from path to either eventhubname or eventHubName, the function executes locally, but when I deploy it via "func azure functionapp publish", it doesn't receive any invocations when deployed to the current Beta of Azure Functions in Azure (Runtime version: 2.0.11587.0 (beta)) so it "appears" this is still not usable?
Has anyone got this attribute working (with .NET Core) in Azure?
@creyke I have it working, after modifying it. I don't deploy with func azure functionapp publish, at least not directly, I deploy locally, modify the JSON, then from VS Code, click the little up arrow to publish with the azure functions extension
@onionhammer can i ask what version of azure functions you are running it in? (might differ per region) - and what versions of the dependent packages you are using too?
'beta' runtime on the latest azure functions nuget