Loader Lock error using DirectX AudioVideoPlayback

I am knocking up a small app and need it to play a few sounds here and there. Now, most of them are straight forward wav files, which is not too much of a problem. However, I also have a few clips in mp3 format, and so have ended up using DirectX as a (supposedly) quick way out – DirectX.AudioVideoPlayback gives you access to a whole host of media functionality. So, having found a few examples on the web I dropped some code in and was then presented with the error message:

LoaderLock was detected

Message: DLL '.......\Microsoft.DirectX.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

Scary!! LoaderLock is one of the Managed Debug Assistants (MDAs) that Microsoft introduced in VS2005 to help track down and debug runtime issues in managed code. Anyway, here’s how to get round this issue:

  1. In VS2005, go to Debug > Exceptions (Ctrl + Alt + E)
  2. In the Managed Debugging Assistants section, scroll down till you find the offender (LoaderLock)
  3. Untick the box in the “Thrown” column. This is a per-solution setting, not a global setting!

Hey presto! Error message has gone. OK, I can hear you wondering, what about my app out in the real world – will it crash and bring the world to a standstill? Well apparently this MDA only affects code run under the debugger, so won’t be a problem. Incidentally, I tried turning the LoaderLock back on and mysteriously my app decided it no longer wanted to throw the error. Strange. So you may get away with turning it off, running your app then turning it back on if you are really concerned.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: