Azure IoThub - 类RegistryManager - 方法AddDeviceAsync(设备)抛出错误代码:ArgumentNull;BadRequest

标签 azure azure-iot-hub

注册表的AddDeviceAsync方法抛出异常ArgumentNull。 参数、registryManager和输出参数notjing为空但仍然抛出异常。

异常:{"Message":"ErrorCode:ArgumentNull;BadRequest","ExceptionMessage":"跟踪 ID:adf7e83e7db046969086702500cbe73b-G:2-TimeStamp:03/21/2018 14:09:50"} 方法:ProjectXXX。 NTB.FN.DeviceRegistration.IdentityCreationService.CreateDeviceIdentity() 描述:意外异常

它是否与 Microsoft.Azure.Devices 库相关?

代码

RegistryManager registryManager = null;

void Initialize()
{
    registryManager = RegistryManager.CreateFromConnectionString(AppSetting.IoTHubConnectionString);
}

public async Task<string> CreateDeviceIdentity(string deviceId, string deviceKey)
{
    Device device = new Device(deviceId);
    Device newdevice =  new Device();

    Exception exception = null;
    bool bExceptionHasOccured = false;

    string token = string.Empty;
    string primarySasToken = Base64Encode(deviceKey);
    string secondarySasToken = Base64Encode($"{deviceId}-{deviceId}");
    device.Authentication = new AuthenticationMechanism
    {
        SymmetricKey = new SymmetricKey
        {
            PrimaryKey = primarySasToken,
            SecondaryKey = secondarySasToken
        }
    };
    try
    {
        newdevice = await registryManager.AddDeviceAsync(device);
        break;
    }
    catch (DeviceAlreadyExistsException)
    {
        token = GetDeviceToken(deviceId);
        break;
    }
    catch (IotHubThrottledException e)
    {

    }
    catch (SocketException e)
    {

    }
    catch (Exception e)
    {

    }

    token = newdevice.Authentication.SymmetricKey.PrimaryKey;
    return token;
}

堆栈跟踪 系统参数异常: 在 Microsoft.Azure.Devices.HttpClientHelper+d__36.MoveNext (Microsoft.Azure.Devices,版本=1.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35) 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089) 在 Microsoft.Azure.Devices.HttpClientHelper+d__121.MoveNext (Microsoft.Azure.Devices,版本=1.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35) 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089) 在 System.Runtime.CompilerServices.TaskAwaiter1.GetResult (mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089) 在 ProjectXXX.NTB.FN.DeviceRegistration.IdentityCreationService+d__6.MoveNext (ProjectXXX.NTB.FN.DeviceRegistration,版本=1.0.0.0,文化=中性,PublicKeyToken=nullProjectXXX.NTB.FN.DeviceRegistration,版本=1.0.0.0,文化=中性,PublicKeyToken = null:D:\ProjectXXX\ProjectXXX.NTB\ProjectXXX.NTB\DeviceRegistrationLib\ProjectXXX.NTB.FN.DeviceRegistration\IdentityCreationService.csProjectXXX.NTB.FN.DeviceRegistration,版本= 1.0.0.0,文化=中性, PublicKeyToken=null: 122)

最佳答案

当我将 Microsoft.Azure.Devices 从 1.5.1 降级到 1.3.2 时,它起作用了

关于Azure IoThub - 类RegistryManager - 方法AddDeviceAsync(设备)抛出错误代码:ArgumentNull;BadRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49409304/

相关文章:

azure - 在 Azure Web 应用程序中使用 SSL

azure - 在azure逻辑应用程序中如何获取url编码数据的键和值

c# - Windows IoT、IoT Hub、流分析、Azure SQL、Power BI - 什么是正确的路径?

azure - 使用 Windows Phone 操作系统的 windowsazure 教程中出现 "GetStartedWithData"异常错误

azure - 如何处理 AZcopy 失败的文件传输

c - IoT Hub 连接字符串在 azure-iot-sdk-c 示例中不起作用

azure - 使用 Azure 设备预配服务的 REST API 注册设备?

azure - 使用流分析将数据从 IoT 中心传输到 Cosmos DB 会出现分区错误

azure - Rust应用程序如何将云到设备的消息发送到旨在到达设备的IoTHub?

bash - 如何在不手动配置的情况下使用databricks-cli