2

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?

Pain
  • 185
  • 1
  • 2
  • 14
  • Bad image sounds for me like it could be the sound file.did you try and use an other sound file.or mybe try a .wav – Creator Oct 12 '14 at 14:58
  • `BadImageFormatException` is usually a 32-bit/64-bit issue. Are the DirectX libraries you're referencing the same bitness as your application? – pmcoltrane Oct 12 '14 at 15:28
  • Tried a .wav file-didnt work. I set Target CPU to x86 and now I get 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."*** – Pain Oct 12 '14 at 17:31
  • 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? – Pain Oct 12 '14 at 18:04
  • See [this](http://blogs.msdn.com/b/chuckw/archive/2010/12/09/directx-and-net.aspx) post for details on the status and limitations of the legacy Managed DirectX 1.1 assemblies. – Chuck Walbourn Oct 14 '14 at 21:50

1 Answers1

4

You are using the olden Managed DirectX wrappers. Targeted to run on .NET 1.1, a framework version that never supported 64-bit code. These wrappers have been deprecated a long time ago, the 2.0 version never made it out of beta.

Changing your EXE's Platform Target to x86 is required, there is no 64-bit version of Managed DirectX and the DLLs contain native 32-bit code written in Managed C++. Furthermore, if you target .NET 4.0 or higher then you have to use a .config file that says that it is okay to load such an ancient assembly that expects native code to run well on .NET 1.1. It should look like this:

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

The useLegacyV2RuntimeActivationPolicy attribute suppresses the error message you got. Whether it can actually run on 4.0+ isn't that clear, nobody uses these wrappers anymore. The usual advice is to switch to SharpDX or SlimDX instead.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • The .config file didn't work I get another error "HResult=-2146232799" something about mixed assembly. I think I'll switch to SharpDX. Thank you. – Pain Oct 12 '14 at 20:53