AccessViolationException from DeviceWatcher.GetBackgroundTrigger

1

Sometimes (though rarely) I get a System.AccessViolationException from the following line of code

var background = deviceWatcher.GetBackgroundTrigger(new List<DeviceWatcherEventKind> { DeviceWatcherEventKind.Add, DeviceWatcherEventKind.Remove, DeviceWatcherEventKind.Update });

System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Visual Studio screenshot

What should I be doing differently to prevent this exception?

uwp
bluetooth-lowenergy
asked on Stack Overflow Feb 26, 2018 by dumbledad

1 Answer

0

Since your issue is not 100% reproduce, we cannot reproduce your issue on our side. So that this should not be the code issue.

Actualy this issue shouldn't happen in managed code. You can try setting Visual Studio Debugger to bypass this exception:

Tools menu ->Options -> Debugging -> General -> Uncheck this option "Suppress JIT optimization on module load"

More details you could reference this similar thread.

answered on Stack Overflow Feb 27, 2018 by Sunteen Wu

User contributions licensed under CC BY-SA 3.0