gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:19:09 24 4
gpt4 key购买 nike

注册表的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.TaskAwaiter
1.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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com