c# - 使用 DirectX 播放音频时加载程序锁定异常

标签 c# .net visual-studio exception directx

我正在尝试使用 DirectX dll 播放音频文件。

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

但是检测到loader锁异常如下图: 我不是分析堆栈跟踪的专家。如何分析和解决加载程序锁定问题?

检测到 LoaderLock

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.

堆栈跟踪:

'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).

编辑: 我尝试禁用加载程序锁定异常。它使异常消失,但文件仍然无法播放。

有什么提示吗?

最佳答案

从本质上讲,当前版本的 DirectX 不能很好地与当前版本的 Visual Studio 配合使用。

DirectX 9.0c 不能很好地与 Visual Studio 配合使用。您可以做的是完全防止抛出异常。要做到这一点:单击 Debug->Exceptions... 菜单项,打开“Managed Debugging Assistant”项,然后取消选中“LoaderLock”标签旁边的框。

尽管这不是最详尽的方法,但实际上这几次救了我一命。更好的方法是使用 DirectX 10,但并非每个人都拥有 Vista 及更高版本。

关于c# - 使用 DirectX 播放音频时加载程序锁定异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5650025/

相关文章:

c# - 将 Dictionary<T> 绑定(bind)到 WPF 列表框

.net - 我们可以用 Electron 边缘js强制加载.NET 4.7.2吗? .Net 4.5.2 在使用 TLS 1.0 时存在安全问题

regex - Visual Studio regex 使用宏删除 VB.NET 代码中的所有注释和空行

asp.net - 如何动态创建UpdatePanel触发器

c# - 将对象实例写入 C# 的工具(用于单元测试)

c# - 如何将 OpenAPI 生成器与公司代理一起使用?

c# - 没有模型属性的 Entity Framework 映射结构/复杂类型

.net - LINQ-在可为空的列上连接表

c++ - 使用 Visual Studio 2013 直接从 std::ostringstream 获取 const char * 时出现意外结果

c# - 如何将多个 View 的DataContext设置为ViewModel的一个实例