1

We use Azure SDK to create Resource groups, iot hubs and devices.

For example:

iotHubDescription = await iotHubClient.IotHubResource.CreateOrUpdateAsync(resourceGroupName, iotHubName,
            iotHubDescription);

or

var device = await registryManager.AddDeviceAsync(new Device(azureDevice.DeviceId));

I've found how to validate Iot Hub name before create it:

var info = await iotHubClient.IotHubResource.CheckNameAvailabilityAsync(new OperationInputs(iotHubName));

but can't find how to validate device id.

So, question is: How to validate Iot device id from Azure SDK?

Vadim
  • 82
  • 8

1 Answers1

1

You need to catch using the Exception,

try
{
   simulatedDevice = await registryManager.AddDeviceAsync(new Device(simulatedDeviceId));}
   catch (DeviceAlreadyExistsException)
   {
    simulatedDevice = await registryManager.GetDeviceAsync(simulatedDeviceId);
    Console.WriteLine("Retrieving existing device id");
   }
}
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396