The problem is very likely that you are creating COM objects (in this case the DMO Resampler) on a STAThread (which will be the case if you are using WinForms or WPF) and then passing them to NAudio output driver models that will attempt to access them on a background thread, which is not allowed.
It is a very annoying problem to work around, since if you set your GUI thread to be MTAThread, other stuff will break (e.g. open file dialogs). Your main options are as follows:
- Stick with using WaveOut which has windowed callbacks. You will also be able to use WasapiOutGuiThread, which is an experimental class I added to the demo project recently. This is by far the easiest solution. Is there any reason you really need to use DirectSound?
- Don't have a ResamplerDmoStream in your audio pipeline. Use WaveFormatConversionStream instead, or simply let WASAPI insert one (which it does automatically)
- Create a background thread which will be used for your audio playback, and send messages from your GUI thread to it, telling it you want to start, stop, reposition etc. This unfortunately is a fairly complicated option.