Mysterious error in DirectX sample...  
Author Message
prog.gabi





PostPosted: Visual C# General, Mysterious error in DirectX sample... Top

This concerns the C# version of DirectX SDK (October 2006) sampler, in particular the CaptureSound sample. It works fine as is, but when I try to deploy it (either regular or ClickOnce procedure) the resulting program bombs. The error message on debugging is

LoaderLock was detected
Message: 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.

I thought this was precisely the kind of thing that managed code would prevent! Can anybody help !



Visual C#8  
 
 
ahmedilyas





PostPosted: Visual C# General, Mysterious error in DirectX sample... Top

I remember this. I can't remember how I fixed it now!

I'm guessing you are trying to use .NET Framework 2.0 you should try to convert the project to VS2005 and see if that helps.

I would also try to remove the MDX refereneces and see if you can re-add them with the latest version, should it exist. From what I have also read, this only happens within the VS IDE when running the application within.



 
 
prog.gabi





PostPosted: Visual C# General, Mysterious error in DirectX sample... Top

Thank you for trying to help. Unfortunately, I am already on VS2005, and the version of DirectX I have is 9.0c, which I understand to be the latest one.

My situation is that the application works fine from within the VS IDE. It is only when I deploy it, and install it on my own computer, that it bombs.


 
 
ahmedilyas





PostPosted: Visual C# General, Mysterious error in DirectX sample... Top

sure. I remember this a while ago, last year actually. I honestly cannot remember how I resolved it. Can you post the line it fails at

 
 
prog.gabi





PostPosted: Visual C# General, Mysterious error in DirectX sample... Top

private void WaitThread()

{

while(Capturing)

{

//Sit here and wait for a message to arrive

NotificationEvent.WaitOne(Timeout.Infinite, true);

RecordCapturedData();

}

}

[This is called by]

// Create a thread to monitor the notify events

if (null == NotifyThread)

{

NotifyThread = new Thread(new ThreadStart(WaitThread));

Capturing = true;

NotifyThread.Start();

// Create a notification event, for when the sound stops playing

NotificationEvent = new AutoResetEvent(false);

}


 
 
prog.gabi





PostPosted: Visual C# General, Mysterious error in DirectX sample... Top

I am glad to say that I was able to solve the problem myself. I found out, in debugging, that the problem was that when WaitThread is called (top of the above code sample), NotificationEvent is still null, because this thread hasn't heard the news yet. Accodingly, I inserted an additional line (see top of above code sample):

private void WaitThread()

{

while (NotificationEvent == null);

to give the Thread time to catch up. This solves the problem, and the program runs like a charm.