views:

71

answers:

2

I just tried to run the NAudio demos and I'm getting a weird error:

System.BadImageFormatException: Could not load file or a
ssembly 'NAudio, Version=1.3.8.0, Culture=neutral, PublicKeyToken=null' or one o
f its dependencies. An attempt was made to load a program with an incorrect form
at.
File name: 'NAudio, Version=1.3.8.0, Culture=neutral, PublicKeyToken=null'
   at NAudioWpfDemo.AudioGraph..ctor()
   at NAudioWpfDemo.ControlPanelViewModel..ctor(IWaveFormRenderer waveFormRender
er, SpectrumAnalyser analyzer) in C:\Users\Admin\Downloads\NAudio-1.3\NAudio-1-3
\Source Code\NAudioWpfDemo\ControlPanelViewModel.cs:line 23
   at NAudioWpfDemo.MainWindow..ctor() in C:\Users\Admin\Downloads\NAudio-1.3\NA
udio-1-3\Source Code\NAudioWpfDemo\MainWindow.xaml.cs:line 15

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\M
icrosoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure lo
gging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus
ion!EnableLog].

Since the last time I used NAudio demos I have changed from 32bit Windows XP to 64bit Windows 7. Would this cause this issue? Its very annoying as I was about to try my hand at audio in C# again

+3  A: 

I have no experience with NAudio, but the exception you mention most often occurs when there is a bitness issue. Meaning that NAudio perhaps is compiled for 32 bit only, and you run 64 bit.

To try to fix this, in compilation properties for your project, set the output to be 32 bit (x86).

driis
that fixed it thanks :) [correct answer tick to Driis because apparently his answer is 'older' or first :)
Kurru
+3  A: 

Your program is trying to load a 32-bit DLL into a 64-bit process (or vice versa). On Windows, a 32-bit program can only load a 32-bit DLL and a 64-bit program can only load a 64-bit DLL.

Your program is probably targeting AnyCPU as the platform, so the compiler emits IL which, at runtime, becomes either a 32- or 64-bit process based on your platform. The DLL you're using (NAudio) is probably built for the x86 platform only.

In your project properties, try forcing the platform to be x86.

Chris Schmich