Azure/azure-iot-sdk-csharp

[Bug Report]RegistryManager.GetDeviceAsync() returns null

Gamecock opened this issue · 1 comments

Context

  • OS, version, SKU and CPU architecture used: Azure Function Dotnet isolated Windows
  • Application's .NET Target Framework : net8.0
  • Device: N/A
  • SDK version used:

Description of the issue

RegistryManager.GetDeviceAsync (string deviceId) returns a null if device is not found.
Per Code Expected DeviceNotFoundException

        {
            if (Logging.IsEnabled)
                Logging.Enter(this, $"Getting device: {deviceId}", nameof(GetDeviceAsync));
            try
            {
                if (string.IsNullOrWhiteSpace(deviceId))
                {
                    throw new ArgumentException(IotHubApiResources.GetString(ApiResources.ParameterCannotBeNullOrWhitespace, "deviceId"));
                }

                EnsureInstanceNotClosed();
                var errorMappingOverrides = new Dictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>()
                {
                    { HttpStatusCode.NotFound, async responseMessage => new DeviceNotFoundException(await ExceptionHandlingHelper.GetExceptionMessageAsync(responseMessage).ConfigureAwait(false)) }
                };

                return _httpClientHelper.GetAsync<Device>(GetRequestUri(deviceId), errorMappingOverrides, null, false, cancellationToken);

Code sample exhibiting the issue

[Fact]
public async Task TestRegistryManager()
{
    var registry = RegistryManager.CreateFromConnectionString(connectionString);

    await Assert.ThrowsAsync<DeviceNotFoundException>(async () => await registry.GetDeviceAsync("IDoNoTExist") );
}

Console log of the issue

Follow the instructions here to capture SDK logs.
Don't forget to remove any connection string information!

Documentation update to be clear non this behavior might be sufficient, but the DFE matches what is received from rest of SDK.