I'm starting with IoT Hub and Azure services. I'm following this quickstart tutorial: Quickstart: Send telemetry from a device to an IoT hub and read it with a back-end application (.NET)
I created a Free Tier IoT Hub in my Azure account and registered a device using Azure Cloud Shell. Now I'm developing a "starter" library send D2C messages and I can see that it is possible to read sent messages. I have problems with the last step, it seems that the code is written in C# 8, but I'm developing with VS 2017 and get an error in a await foreach
loop.
The sample code is here, and this is the code I want to change to C# 7:
private static async Task ReceiveMessagesFromDeviceAsync(CancellationToken cancellationToken)
{
string connectionString = "{MyConnectionString}";
await using EventHubConsumerClient consumer = new EventHubConsumerClient(EventHubConsumerClient.DefaultConsumerGroupName, connectionString, EventHubName);
Console.WriteLine("Listening for messages on all partitions");
try
{
await foreach (PartitionEvent partitionEvent in consumer.ReadEventsAsync(cancellationToken))
{
...
}
}
catch (TaskCanceledException)
{
...
}
}
This is the error I get in Visual Studio:
foreach statement cannot operate on variables of type 'IAsyncEnumerable' because 'IAsyncEnumerable' does not contain a public instance definition for 'GetEnumerator'
Is it possible to rewrite this line to use with C# 7?
Some details:
- Visual Studio Professional 2017
- Library target framework:
.NET Core 2.1.NET 4.7.2