【发布时间】:2011-02-03 18:47:57
【问题描述】:
我正在尝试编写一个应用程序,该应用程序从计算机上的默认录音设备接收声音。当运行从我的托管代码访问 DirectX 的任何代码时,我收到此错误:
DLL 'C:\Windows\assembly\GAC\Microsoft.DirectX.DirectSound\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.DirectSound.dll' 正在尝试在 OS Loader 锁内进行托管执行。不要尝试在 DllMain 或图像初始化函数中运行托管代码,因为这样做会导致应用程序挂起。
DevicesCollection coll = new DevicesCollection();
和
Device d = new Device(DSoundHelper.DefaultCaptureDevice);
和
Capture c = new Capture(DSoundHelper.DefaultCaptureDevice);
都会导致 LoaderLock MDA 弹出并告诉我有问题。我已经在互联网(包括stackoverflow)上搜索了这个问题的解决方案,但大多数人只是说关闭警告,这不起作用。当我关闭警告时,会抛出一个通用的 ApplicationException,这甚至更没用。我也看到了this question 的答案,但这并没有帮助,因为他说要删除导致错误的代码。其他人说“修复你的代码”。
我的问题是:
如何从 C# 调用任何(最好是托管的)DirectX 代码而不出现此错误?
编辑:这是我得到的堆栈跟踪:
at Microsoft.DirectX.DirectSound.Device..ctor(Guid guidDev)
at Autotuner.fMain.button1_Click(Object sender, EventArgs e) in C:\\Users\\Scott\\Documents\\Visual Studio 2008\\Projects\\Autotuner\\Autotuner\\Form1.cs:line 17
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Autotuner.Program.Main() in C:\\Users\\Scott\\Documents\\Visual Studio 2008\\Projects\\Autotuner\\Autotuner\\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
【问题讨论】:
-
例外是好的,发布 StackTrace。
-
它的字面意思是 ApplicationException 并带有消息“应用程序中的错误”
-
Scott,你有没有解决过这个问题?我也面临同样的问题。
标签: c# directx loaderlock