Skip to content

[Bug Report]RegistryManager.GetDeviceAsync() returns null #3473

@Gamecock

Description

@Gamecock

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions