[Visual Studio] Event hub trigger not working with VS2017 functions tooling
Hi,
When I create Event Hub triggered functions using VS2017 functions tools I am getting following error when running function:
Function Error: Value cannot be null. Parameter name: receiverConnectionString
This my run method argument-
public static void Run([EventHubTrigger("abc", Connection = "eventhub")]string[] myEventHubMessages, ExecutionContext exCtx, TraceWriter log)
My local.settings.json- { "IsEncrypted": false, "Values": { "eventhub":"Endpoint=acbcdefgj",
} }
The eventhub parameter is missing the leading double quote before "Endpoint=" in the local.settings.json
Try: `{ "IsEncrypted": false, "Values": { "eventhub":"Endpoint=acbcdefgj", } }
That was a typo here..it is actually there in code. But still not working.
For the C# tooling I had to upgrade to prerelease version because WebJobs.ServiceBus was locked to WebJobs 2.0, now it's 2.1.0-beta4
Hi folks. I think I'm having exactly the same issue.
Some background - I'm trying to get up and spinning with a simple IoT project as follows:
- Raspberry Pi Running Windows 10 IoT;
- Azure IoT Hub created, with my Raspberry Pi registered as an device for this IoT Hub though the Azure Portal;
- Simple "background application" written in Visual Studio and deployed onto the Raspberry Pi that publishes messages to the Azure IoT Hub;
- An Azure Function of type eventHubTrigger connected to the IoT Hub;
- Messages received by the function will be parsed and written to Azure Table Storage;
- PowerBI analytics on the Table Storage.
I've got it working as far as step 4 - where I've hit this problem.
Using VS2017 functions tooling to create "vanilla" Event Hub function as follows:
`using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Host; using Microsoft.Azure.WebJobs.ServiceBus;
namespace AzureFunctionProject
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([EventHubTrigger("EventHubCompatibleName",
Connection = "EventHubCompatibleEndpoint")]
string myEventHubMessage,
TraceWriter log)
{
log.Info($"C# Event Hub trigger function processed a message: {myEventHubMessage}");
}
}
}`
In this case the
I've managed to build and deploy the function from Visual Studio successfully, however when I navigate to Function1 in the Azure Portal, a pink pop out box is displayed with the following red text:
Error: Function ($Function1) Error: Value cannot be null. Parameter name: receiverConnectionString. Session Id: ee8835a6c9964882926e643a1fe88a02 Timestamp: 2017-10-14T16:19:40.771Z
I cannot find any documentation relating to "receiverConnectionString" online.
I'm running: Microsoft Visual Studio Professional 2017 Version 15.3.3 VisualStudio.15.Release/15.3.3+26730.12 Microsoft .NET Framework Version 4.7.02046 WebJobs Tools v1.0.0 15.0.30923.0
Any ideas would be much appreciated.
My issue was functionTimeout more than 10:00 in host.json.
@IshaBatra and @Vesperpiano are you still facing issues? From above one big thing is if your C# Attribute mentiones connection MyConnectionString you have to make sure your local.settings.json file also has a Values for MyConnectionString. I'm not sure what the constraints are for scope of the connectionString, but I know in my development I do a namespace-level connection string (the connection string doesn't end with Entity-...
Let me know - unable to repro on my end
@jeffhollan well, I'm facing this issue. my local.settings.json is { "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;...", "AzureWebJobsDashboard": "", "EventHubConnection": "Endpoint=sb://..." } }
public static class Function1
{
[FunctionName("Function1")]
public static void Run([EventHubTrigger(
"<my event hub name>" ,
Connection = "EventHubConnection")]
string myEventHubMessage, TraceWriter log)
{
log.Info($"C# Event Hub trigger function processed a message: {myEventHubMessage}");
}
}
Figured it out: originally I misconfigured the connection string, and got the "receiverConnectionString" error. I fixed the config but VS didn't change function.json on F5 and still complained about bad connection string. I had to clean the solution, and next time when I did F5 and function.json was (re)created, it had correct configuration values and it ran successfully.
I am still seeing this issue. Locally, things work fine, deployed it get the System.ArgumentNullException : Value cannot be null. Parameter name: receiverConnectionString. I removed the "generatedBy" property from the json file created by VS. Still, no love. Please advice how to proceed.
Any luck with this? ALso having the issue
@TheLever @NucleoTech if working locally but not when published be sure to verify you have the value set as an Application Setting in the Azure Function after publishing. The local.settings.json is your local version of all environment variables to use in development. After publishing this need to reflect in your Application Settings in Azure which has the environment variables. We are tracking work items to automatically prompt and help guide users when settings exist locally but not in cloud when publishing (@cartermp as FYI who is helping track this). Let me know if that resolves the issue or clears things up.
@jeffhollan I had similar issue (logged as #2915). But eventually I found out that when deploying from VS2017 the function.json in Azure did not contain correct bindings to the function entry point. When I corrected the bindings with Kudu, all was fine. It would however be great if the error messages could be more clear.
Hmm... you shouldn't have to touch Kudu for apps published from VS2017 as the binaries should be published as part of the app.
@jeffhollan The binaries are published fine but it seems the function.json not updated automatically to reflect the function parameter bindings. Not sure if it is supposed to? In my FunctionApp setting runtime ~1 VS2017 project I am using NuGet packages: Microsoft.NET.Sdk.Functions (1.0.13) Microsoft.Azure.WebJobs.ServiceBus (2.2.0)
See my other issue here: https://github.com/Azure/azure-functions-host/issues/2915
The function.json file is generated as part of the build step as part of the Microsoft.NET.Sdk.Functions package and should be published with the app. It is generated off of the Attributes included in the function method. What changes did you have to make to the function.json in Kudu? The function.json included in the referenced issue appears to be valid from what I can see.
@jeffhollan
Yes I see that the function.json is generated as part of the build step and then uploaded as part of the publish. Here is the function.json after publish:
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.13",
"configurationSource": "attributes",
"bindings": [
{
"type": "eventHubTrigger",
"path": "platformmanagementiothub",
"consumerGroup": "hotpath",
"connection": "PlatformManagementIotHub_events",
"name": "myEventHubMessage"
}
],
"disabled": false,
"scriptFile": "../bin/PlatformManagement.AzureFunctions.PlatformEventHandler.dll",
"entryPoint": "Nucleo.GreatGuide.PlatformManagement.AzureFunctions.PlatformEventHandler.HandleDeviceEvent.Run"
}
and this is the function: ` [FunctionName("PlatformEventHandler")] public static void Run( [EventHubTrigger("platformmanagementiothub", Connection = "PlatformManagementIotHub_events", ConsumerGroup = "hotpath")]EventData myEventHubMessage, [Table("Lookups")] CloudTable lookupsTable, [Table("Platform")] CloudTable platformTable, [Table("IotEventErrorBin")] CloudTable iotEventErrorBinTable, [Table("RawEventErrorBin")] CloudTable rawEventErrorBinTable, [Table("RawEvent")] CloudTable rawEventTable, TraceWriter log) { }
`
So the function.jso above is being generated with the v1 .NET Framework path. I can tell as the path parameter has been renamed to eventHubName in v2 .NET Core runtime. I'm wondering if your issues may be coming from the fact of a version mismatch in the cloud environment (assuming you have function version set to "beta").
If you look at the .csproj file in VS you should see both a target framework and function runtime version property. It should be set to netstandard2.0 and v2 respectively I believe. If you see net46 your local tools are likely building the function.json based on v1 rules
@jeffhollan In Azure, the runtime is Runtime version: 1.0.11820.0 (~1) My VS project has TargetFramework net471, but has no function runtime version property.
Good day, I am facing the 'Value cannot be null. Parameter name: receiverConnectionString' issue, using application insights I am seeing the following for the exception settings.
Event time | 13/06/2018, 13:53:15 |
-- | -- | --
Message | Error indexing method 'RouteFunction.Run' Value cannot be null. Parameter name: receiverConnectionString |
Exception type | System.ArgumentNullException |
Failed method | Microsoft.Azure.WebJobs.ServiceBus.EventHubConfiguration.AddReceiver |
SDK version | azurefunctions: 1.0.11820.0 |
Client IP address | 0.0.0.0 |
Sample rate | 1 |
Device type | PC |
Cloud role name | functionapp20180607122611 |
Cloud role instance | eaa8a142a5904439e98660d4e1f397c697621338b527dee857aed3a11c7ece25 |
Telemetry type | exception |
Problem Id | System.ArgumentNullException at Microsoft.Azure.WebJobs.ServiceBus.EventHubConfiguration.AddReceiver |
Assembly | Microsoft.Azure.WebJobs.ServiceBus, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 |
Severity level | Error
I have been stuck on this for a while, if someone could kindly point me in the right direction it would be much appreciated.
@NucleoTech the 471 means that it's targeting .NET Framework 4.7.1 which is great - our v1 runtime. Just make sure the Azure Function in the cloud in Function Settings is set to ~1 and not "beta". If it's set to beta (there's a corresponding application setting too) you have a runtime mismatch which could explain issues.
@njabulomp This is saying that you don't have an environment variable set for the Event Hubs connection string. In your C# attribute you should have something like Connection = "SomeEnvironmentVariableName" - that would correspond to a value in local.settings.json locally that contains connection string. In the cloud environment it means you need an Application Setting called SomeEnvironmentVariableName (in this case) where the value is the conneciton string. If you don't have that application setting set you will get this error that it has a null connection string variable.