Loader Lock Exception while playing audio using DirectX
Asked Answered
S

2

5

I am trying to play and audio file using DirectX dll.

  Audio.FromFile("Message 1.mp3").Play();

But a loader lock exception is detected as shown below: I am not an expert in analyzing the stack trace. How to analyze and solve the loader lock problem ?

LoaderLock was detected

Message: DLL 'C:\Windows\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\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.

Stack Trace:

'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'E:\Modules\ToDoApp\bin\Release\ToDoApp.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC\Microsoft.DirectX.AudioVideoPlayback\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.AudioVideoPlayback.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x127c has exited with code 0 (0x0).
The thread 0x210 has exited with code 0 (0x0).
'ToDoApp.vshost.exe' (Managed): Loaded 'E:\Modules\ToDoApp\bin\Release\ToDoApp.exe', Symbols loaded.
The thread 0x15a8 has exited with code 0 (0x0).

Edit: I tried disabling the loader lock exception. It makes the exception vanish, but still the file doesn't play.

Any hints ?

Shire answered 13/4, 2011 at 13:26 Comment(0)
I
6

Essentially, the current version of DirectX doesn't play well with the current version of Visual Studio.

DirectX 9.0c does not play nicely with Visual Studio. What you can do is to prevent the exception from being thrown at all. To do that: Click the Debug->Exceptions... menu item, open up the "Managed Debugging Assistant" item, and uncheck the box next to the "LoaderLock" label.

This actually saved me on a couple of occasions eventhough it isn't most elaborate approach. A better approach would be to use DirectX 10 but not everybody has Vista and above.

Institute answered 13/4, 2011 at 13:38 Comment(5)
Yes i did that few mins back. Exception is no longer thrown, but again the file is not played ..!!Shire
Try this var audio = Audio.FromFile("C:\sound1.mp3", false) \\ The False sets autorun to false and then audio.Play(). Also make sure that Microsoft.DirectX.dll and Microsoft.DirectX.AudioVideoPlayback is referenced.Institute
Also make sure thatDirectX 9.0 SDK Update is installed, without SDK update, there are problems with the playback since the volume is always set to something like -100. Install the update and try setting the volume to 0.Institute
Ok will try that and let you know. Thanks :)Shire
Actually this is the discussion thread on MSDN that helped me get playback right when I had a similar problem: social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/…Institute
W
3

The LoaderLock is a known bug with Managed DirectX. You can work around this by disabling it in the Visual Studio exceptions list under Managed Debugging Assistants.

The better workaround is to switch to a supported DirectX library such as SlimDX or XNA.

Warrantee answered 13/4, 2011 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.