Azure / azure-iot-sdk-csharp

A C# SDK for connecting devices to Microsoft Azure IoT services
Other
470 stars 492 forks source link

[Bug Report] DPS query API does not populate enrollment assignment information #3478

Open dadude999 opened 1 day ago

dadude999 commented 1 day ago

Context

Description of the issue

The DPS SDK contains wrapper methods around two DPS APIs: (a) query all enrollments for a DPS instance (b) get a single enrollment from the DPS instance

Method (b) works correctly, but when using version (a), the enrollment objects are all missing the RegistrationState information. This causes us to have to retrieve each individual enrollment rather than querying the list once and using the information as-is.

Code sample exhibiting the issue

ProvisioningServiceClient provisioningServiceClient =
    ProvisioningServiceClient.CreateFromConnectionString("<insert_connection_string_here>");

IndividualEnrollment goodResult = await provisioningServiceClient.GetIndividualEnrollmentAsync("<pick_a_regstration_id>");
// here, goodResult.RegistrationState is a valid object containing IoT Hub assignment details

Query query = provisioningServiceClient.CreateIndividualEnrollmentQuery(new QuerySpecification(string.Empty));
while(query.HasNext())
{
    QueryResult result = await query.NextAsync();
    IReadOnlyList<DeviceRegistrationState> badResults = result.Items.OfType<IndividualEnrollment>()
        .Select(enrollment => enrollment.RegistrationState).ToList();
   // here, every item in badResults will be null
}