1

OS: Windows 8.1 64

I tried to play multiple sounds in VB.Net with DirectX, there are no errors in my code. The problem is whenever the event is fired I get this error

System.BadImageFormatException was unhandled Message: An unhandled exception of type 'System.BadImageFormatException' occurred in System.Windows.Forms.dll Additional information: Could not load file or assembly 'Microsoft.DirectX.AudioVideoPlayback.dll' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

Then I set Target CPU to x86 and I got this error

System.IO.FileLoadException was unhandled Message: An unhandled exception of type 'System.IO.FileLoadException' occurred in System.Windows.Forms.dll Additional information: Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

So far I have tried uninstalling-reinstalling DirectX SDK, Installing everything that has to do with DirectX and different sound files (.wav). Also I had to browse to load the .dlls, I couldn't find them under Reference Manager>Assemblies but now I cant even load them through browse so I use Imports Microsoft.DirectX.AudioVideoPlayback It will let me Import the rest .dlls except(Reference Manager wont even open them):

Microsoft.DirectX.AudioVideoPlayback.dll
Microsoft.DirectX.dll
Microsoft.DirectX.DirectSound.dll

the ones that I need. Is there a way to clean re-install them?

Target Framework: .Net Framework 4.5

CODE:

Dim MySound1 As New Microsoft.DirectX.AudioVideoPlayback.Audio("D:\path\sound_file.mp3")

MySound1.Play()

Let me know if you need to know anything else.

UPDATE: I changed the Target Framework to .Net Framework 3.5 and it works fine but only if the CPU Target is set to x86! Why is that?

4

1 回答 1

4

您正在使用旧的托管 DirectX包装器。目标是在 .NET 1.1 上运行,这是一个从不支持 64 位代码的框架版本。这些包装器很久以前就被弃用了,2.0 版本从未退出测试版。

需要将 EXE 的平台目标更改为 x86,没有 64 位版本的托管 DirectX,并且 DLL 包含用托管 C++ 编写的本机 32 位代码。此外,如果您的目标是 .NET 4.0 或更高版本,那么您必须使用一个 .config 文件,该文件表明可以加载这样一个期望本机代码在 .NET 1.1 上良好运行的古老程序集。它应该如下所示:

<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

useLegacyV2RuntimeActivationPolicy属性抑制您收到的错误消息。它是否真的可以在 4.0+ 上运行还不是很清楚,没有人再使用这些包装器了。通常的建议是改用 SharpDX 或 SlimDX。

于 2014-10-12T19:45:49.617 回答