locked
EventHubClient.CreateFromConnectionString() - ConfigurationErrorsException RRS feed

  • Question

  • Hi.

    I need a little help with EventHubClient.

    I have created IoT hub and I can see that the events I send get into Azure.

    Next step is to create a listener. I have a console app that does the following:

                string connectionString = "HostName=XXX.azure-devices.net;DeviceId=XXX;SharedAccessKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
                string iotHubD2cEndpoint = "messages/events";
                var eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, iotHubD2cEndpoint);

    the connection string is the "Connection string—secondary key" copied from the portal, is this correct? or should it be primary?

    anyways, I tried both, and I always get the following exception on CreateFromConnectionString():

    System.ArgumentException occurred
      HResult=0x80070057
      Message=Some of the configuration is missing a required component. Make sure all or none of the following properties are defined as part of 'Microsoft.ServiceBus.ConnectionString' key within 'appSettings' section, or Windows Azure configuration settings: [SharedAccessKeyName,SharedAccessKey]
      Source=Microsoft.ServiceBus
      StackTrace:
       at Microsoft.ServiceBus.ServiceBusConnectionStringBuilder.InitializeFromKeyValueManager(KeyValueConfigurationManager manager)
       at Microsoft.ServiceBus.Messaging.EventHubClient.CreateFromConnectionString(String connectionString, String path)
       at IoTHubListener.Program.Main(String[] args) in D:\WS\IoTHubListener\IoTHubListener\Program.cs:line 18
    
    Inner Exception 1:
    ConfigurationErrorsException: Some of the configuration is missing a required component. Make sure all or none of the following properties are defined as part of 'Microsoft.ServiceBus.ConnectionString' key within 'appSettings' section, or Windows Azure configuration settings: [SharedAccessKeyName,SharedAccessKey]
    

    what am I doing wrong there?

    thanks

    Tuesday, March 21, 2017 5:31 PM

Answers

  • Hi Tridy,

    it looks like is missing a SharedAccessKeyName component in the connection string. 

    the following screen snippet shows where you can take a connection string for Azure IoT Hub:

    Thanks

    Roman



    • Edited by Roman Kiss Tuesday, March 21, 2017 6:35 PM
    • Marked as answer by Тridy Tuesday, March 21, 2017 7:46 PM
    Tuesday, March 21, 2017 6:34 PM

All replies

  • Hi Tridy,

    it looks like is missing a SharedAccessKeyName component in the connection string. 

    the following screen snippet shows where you can take a connection string for Azure IoT Hub:

    Thanks

    Roman



    • Edited by Roman Kiss Tuesday, March 21, 2017 6:35 PM
    • Marked as answer by Тridy Tuesday, March 21, 2017 7:46 PM
    Tuesday, March 21, 2017 6:34 PM
  • Thank you!

    Tuesday, March 21, 2017 7:46 PM