LoaderLock was detected, and turning off the warning does not help

Posted by Scott M. on Stack Overflow See other posts from Stack Overflow or by Scott M.
Published on 2010-04-02T15:39:00Z Indexed on 2010/04/02 15:43 UTC
Read the original article Hit count: 1302

Filed under:
|
|
|

I am trying to write an application that takes in sound from the default audio recording device on a computer. When running any code that accesses DirectX from my managed code i get this error:

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

DevicesCollection coll = new DevicesCollection();

and

Device d = new Device(DSoundHelper.DefaultCaptureDevice);

and

Capture c = new Capture(DSoundHelper.DefaultCaptureDevice);

all cause the LoaderLock MDA to pop up and tell me there is a problem. I have scoured the internet (stackoverflow included) for solutions to this problem, but most people just say to turn off the warning, which does not work. When I turn off the warning, a generic ApplicationException is thrown, which is even less useful. I have seen the answers to this question as well, which didn't help because he said to remove the code that is causing the error. Others have said "fix your code."

My questions are:

how can I call any (preferably managed) DirectX code from C# without getting this error?

© Stack Overflow or respective owner

Related posts about directx

Related posts about c#