0

I am getting below mentioned exception randomly when trying to get DeviceCount property of NAudio Lib in C#.

2015/05/11 Sound - GetDevices failed due to unexpected error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at NAudio.Wave.WaveInterop.waveOutGetNumDevs() at Sound.GetDevices()

Code Snip in c# is given below:

private void GetDevices()
{
    var deviceCount = NAudio.Wave.WaveOut.DeviceCount;
}

Could somebody help us to identify the root cause of this issue and how can we solve it?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
arun jain
  • 51
  • 4
  • You cannot have AV in pure .Net code, so you are using some un managed code, which is having corrupted memory or mismatch in dll to be loaded, provide more details, is it a PInvoke call – Mrinal Kamboj Nov 05 '15 at 08:12
  • Use Windbg to create AV dump with relevant pdb by your side, this will provide the complete details of the Exception stack causing the issue – Mrinal Kamboj Nov 05 '15 at 08:15
  • I am using NAudio Lib from codeplex for getting devices available on system. If you see logs, it indicates that NAudio Lib internally using WIN API waveOutGetNumDevs() to access device count. This win API method is throwing the exception.And this issue is very random. I can't reproduce the issue. – arun jain Nov 05 '15 at 08:24
  • Difficult to guess like this, try following code examples, instead of Codeplex, http://stackoverflow.com/questions/5936434/detecting-audio-input-output-devices-connected-to-system http://www.codeproject.com/Articles/18685/Enumerating-Sound-Recording-Devices-Using-winmm-dl – Mrinal Kamboj Nov 05 '15 at 08:35
  • *"If you see logs"* - Well, we cannot see the logs. Why not attach a full callstack to the question, as this seems to be relevant. Since you are using a 3rd party library, it would also help, if you provided a link to it. – IInspectable Nov 05 '15 at 10:30

0 Answers0