I am using the Raspbian “wheezy” image and I copied over a wav file and played it successfully doing:

aplay test.wav

So then I knocked up this little console application:

using System;
using System.Media;
using System.IO;

namespace SoundPlayingTest
    class MainClass
        public static void Main (string[] args)
            using(var file = new FileStream("test.wav", 
                FileMode.Open, FileAccess.Read, FileShare.Read))
                var player = new SoundPlayer(file);

I expected that to play the wav just like aplay but it finishes (with no error) and I hear nothing from the headphones I have plugged in.

I found this thread "System.Media.SoundPlayer silent" that suggested it wasn't working but was fixed and the workaround suggested there is exactly what I am doing so I am not really any further.

To give some further information I ran:

mono --version

And this was the result:

Mono JIT compiler version (Debian
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors.     www.mono-project.com
TLS:           __thread
SIGSEGV:       normal
Notifications: epoll
Architecture:  armel,vfp
Disabled:      none
Misc:          softdebug 
LLVM:          supported, not enabled.
GC:            Included Boehm (with typed GC and Parallel Mark)

So, is it possible to get SoundPlayer to work (it should play a wav file right?) or is there some alternative I can use in order to play a sound file from mono running on the PI?

(by the way, I installed mono by doing sudo apt-get install mono-complete so I guess I am not missing any dependencies)

  • What language is that?
    – Jivings
    Oct 26, 2012 at 16:56
  • @Jivings I believe that is C# Oct 26, 2012 at 21:14
  • yes, that is correct - c sharp
    – kmp
    Oct 27, 2012 at 12:15
  • 1
    I have just tried this exact code on my Raspberry Pi with Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-4+rpi1) and Raspbian version 3.12.22+ #691 PREEMPT and it appears to work, however at the end of the file it segfaults unless you run it as root. Oct 6, 2014 at 10:49

2 Answers 2


There are allot of sound issues with the Raspberry Pi - and I mono on Pi(or any Linux actually) was no exception.

There has been an issue with this and it is resolved in the master repo.

How to solve the problem? You can try and build mono from the latest source or wait a while until it is pushed into the next update. But it seems mono on "wheezy" does not support audio because ...

p/invokes are broken on raspbian. especially if floating point values are involved

So sources have suggested :

run any non-hard-float os on the pi. or wait for hf support in mono 3.0 packages in debian experimental. couple of weeks for that, imho.


Your sample code played for me, however if I run my console app as sudo, the SSH session hangs and I need to start a new one.

This doesn't happen if not sudo (I need sudo to access i2c)

pi@raspberrypi ~ $ mono --version
Mono Runtime Engine version 3.2.7 (master/d7ce227 Monday 23 December  21:49:08 EST 2013)
Copyright (C) 2002-2013 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  armel,vfp+hard
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen

I also get some audio errors to std out but otherwise the sound plays

*** glibc detected *** mono: double free or corruption (!prev): 0x01b862a8 ***

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) Mono.Audio.AlsaDevice.snd_pcm_hw_params_free (intptr) <0xffffffff>
  at Mono.Audio.AlsaDevice.Dispose (bool) <0x0004f>
  at Mono.Audio.AlsaDevice.Finalize () <0x00027>
  at (wrapper runtime-invoke) object.runtime_invoke_virtual_void__this__ (object,intptr,intptr,intptr) <0xffffffff>
  • The method of process.start aplay works: stackoverflow.com/questions/17288985/…
    – fiat
    May 31, 2014 at 12:12
  • FYI, we found an issue in the mono implementation of Mono.Audio.AlsaDevice where it was not nulling out pointers that it was freeing with snd_pcm_XXX_free calls. We got this same call stack. See bugzilla.xamarin.com/show_bug.cgi?id=24109 for the patch (which has been accepted).
    – chrish
    Oct 28, 2014 at 19:31
  • fantastic - great work!
    – fiat
    Oct 28, 2014 at 23:16
  • Chrish, this problem was fixed around 3.10.x. But came back at the latest version 4+ :(
    – s k
    Nov 27, 2017 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.