Hi Team
I want to pass 3 arguments that i declared them as private readonly objects.
Inside my main class method i get the error on EventHubsConnectionStringBuilder. e.g
private readonly static s_eventHubsCompatibleEndpoint = "'sb://iothb-ns.. ;
private readonly static s_eventHubsCompatiblePath ="testiothubs";
private static EventHubClient s_eventHubClient;
private static async Task Main(string[] args) {
var connectionString = new EventHubsConnectionStringBuilder(s_eventHubsCompatibleEndpoint, s_eventHubsCompatiblePath,
s_eventHubClient = EventHubClient.CreateFromConnectionString(connectionString.ToString()));
"error EventHubsConnectionStringBuilder does not contain constructor for 3 argument. What am i missing here please help. Im trying to readmessage2device.
Rajanikant HawaldarPosted Sep 10, 2019, 4:52 AM
Saravanan GanesanPosted Aug 4, 2023, 8:00 PM
The error you are encountering is because the
EventHubsConnectionStringBuilderclass does not have a constructor that takes three arguments for theEventHubsCompatibleEndpoint,EventHubsCompatiblePath, andEventHubClientvariables.To construct the
EventHubsConnectionStringBuilder, you need to use the correct constructor that takes the connection string or the Event Hub namespace, event hub name, and the shared access key. Here's how you can modify your code:private static readonly string s_eventHubsCompatibleEndpoint = "sb://iothb-ns..";
private static readonly string s_eventHubsCompatiblePath = "testiothubs";
private static readonly string s_sharedAccessKeyName = "YourSharedAccessKeyName";
private static readonly string s_sharedAccessKey = "YourSharedAccessKey";
private static EventHubClient s_eventHubClient;
private static async Task Main(string[] args) {
var connectionStringBuilder = new EventHubsConnectionStringBuilder(
new Uri(s_eventHubsCompatibleEndpoint),
s_eventHubsCompatiblePath,
s_sharedAccessKeyName,
s_sharedAccessKey);
s_eventHubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
// Rest of your code here
}
In this modified code, we are using the appropriate constructor of
EventHubsConnectionStringBuilderthat takes the necessary arguments for constructing the connection string. Replace "YourSharedAccessKeyName" and "YourSharedAccessKey" with the actual values for your Event Hub's shared access policy.Guest UserPosted Sep 10, 2019, 4:58 AM