在我的Xamarin.Forms项目(目前仅支持UWP)中,我们有一个特定于平台的代码,声称可以使用条形码扫描程序。当解决方案在我的" LocalMachine"上运行时,这种逻辑工作正常。在Windows 10上构建 16299 。每次崩溃时都会更新到Windows 10版本 17134 并出现以下异常:
System.Runtime.InteropServices.COMException: 'Error HRESULT E_FAIL has been returned from a call to a COM component.'
Error code (0x80004005)
该等异常来自await EnableScanner()以下行:
private async void Initialize(object sender, RoutedEventArgs e)
{
// create the barcode scanner.
if (await CreateDefaultScannerObject())
{
// after successful creation, claim the scanner for exclusive use and enable it so that data reveived events are received.
if (await ClaimScanner())
{
claimedScanner.ReleaseDeviceRequested += claimedScanner_ReleaseDeviceRequested;
// after successfully claiming, attach the datareceived event handler.
claimedScanner.DataReceived += claimedScanner_DataReceived;
UpdateOutput(ScanningLang.DataReceivedAttached);
claimedScanner.IsDecodeDataEnabled = true;
if (await EnableScanner())
UpdateOutput(ScanningLang.ScanReady);
}
}
else
{
UpdateOutput(ScanningLang.NoBarcodeScanner);
}
}
EnableScanner方法:
private async Task<bool> EnableScanner()
{
if (claimedScanner == null)
return false;
await claimedScanner.EnableAsync();
UpdateOutput(ScanningLang.EnabledBarcodeSuccess);
return true;
}