【发布时间】:2018-04-13 12:11:47
【问题描述】:
我正在开发在 rasberry pi3 上运行的 Windows iot 核心应用程序 我尝试使用以下方法从 azure iot hub 创建/获取设备密钥
public MainPage()
{
systemName = "RaspIot";
this.InitializeComponent();
/* Register for the unloaded event so we can clean up upon exit */
Unloaded += MainPage_Unloaded;
registryManager = RegistryManager.CreateFromConnectionString(connectionString);
AddDeviceAsync().Wait();
}
private static async Task AddDeviceAsync()
{
Device device;
try
{
device = await registryManager.AddDeviceAsync(new Device(systemName));
}
catch (DeviceAlreadyExistsException)
{
device = await registryManager.GetDeviceAsync(systemName);
}
deviceKey = device.Authentication.SymmetricKey.PrimaryKey;
}
如果名称为“RaspIot”的设备已注册,则会引发异常。 这在 .net45 控制台应用程序中运行良好。但在 PI3 的 UWP 应用程序中,抛出异常(在调试时弹出)但未由 catch 捕获)。我应该怎么做?
【问题讨论】:
标签: c# exception raspberry-pi3 windows-10-iot-core