Why does DeviceInformation.FindAllAsync(DeviceClass.AudioCapture) sometime throws "Value does not fall within the expected range"
DeviceInformationCollection dicAllAudioDevices = await DeviceInformation.FindAllAsync(DeviceClass.AudioCapture);
The above code usually works fine, but analytics shows it throws the following exception occasionally from different users:
System.ArgumentException: Value does not fall within the expected range.
Stack Trace:
at System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32, RuntimeTypeHandle) + 0x21
at __Interop.ComCallHelpers.Call(__ComObject, RuntimeTypeHandle, Int32, Int32, Void*) + 0xc2
at __Interop.ForwardComStubs.Stub_129[TThis, TResult] + 0x45
at Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(DeviceClass) + 0x32
Could anyone shed some light on the possible causes of this?Could anyone shed some light on the possible causes of this?
Update[2023-10-27]
I also see the following exception thrown by this statement:
System.ArgumentException: The parameter is incorrect.
Stack Trace:
at System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32, RuntimeTypeHandle) + 0x21
at __Interop.ComCallHelpers.Call(__ComObject, RuntimeTypeHandle, Int32, Int32, Void*) + 0xc2
at __Interop.ForwardComStubs.Stub_139[TThis, TResult](__ComObject, Int32, Int32) + 0x45
at Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(DeviceClass) + 0x32
I have seen the following other exception messages from this statement so far:
- Class not registered (Exception from HRESULT: 0x80040154)
- System.BadImageFormatException: %1 is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
- Unspecified error (Exception from HRESULT: 0x80004005)
- Operation aborted (Exception from HRESULT: 0x80004004) Wonder why this method is so prone to exceptions.