This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Error System.BadImageFormatException When Using WPF Designer

Updated Sep 16, 2022

Reported In

Software

  • LabVIEW

Driver

  • NI-DAQmx

Programming Language

  • Visual Basic .NET

Issue Details

I am using Microsoft Visual Studio with the NI .NET Class Libraries to create a WPF application. When I open the Design view for my .xaml file, I receive the following error: 

System.BadImageFormatException. Could not load file or assembly 'NationalInstruments.DAQmx, Version=9.6.40.292, Culture=neutral, PublicKeyToken=dc6ad606294fc298' as one of its dependencies. An attempt was made to load a program with an incorrect format. Why do I get this error, and how can I resolve it?

Solution

System.BadImageFormatException error often occurs when a 64-bit assembly is opened by a 32-bit application. In this case, Visual Studio is a 32-bit application and the Design view is attempting to load a 64-bit assembly. Visual Studio assemblies are located in the project references tree. 

The first option is to rebuild the assembly or DLL using a 32-bit environment so that it is a 32-bit assembly/DLL. If rebuilding the assembly is not an option, follow the instructions below.

NI .NET Class Library assemblies are installed into three locations:
  • C:\Program Files (x86)\National Instruments\MeasurementStudioVS<version>\DotNET\Assemblies
  • C:\Program Files (x86)\National Instruments\MeasurementStudioVS<version>\DotNET\Assemblies (64-bit)
  • Global Assembly Cache (GAC)
NI recommends referencing assemblies from the Assemblies directory. This will ensure that the assembly with the correct bitness is used when the Design view loads the references. Complete the following steps to update your project references:
  1. Open your Visual Studio DAQmx example project.
  2. Expand References in the Solution Explorer window.
  3. Delete any National Instruments references by pressing <Delete>.
  4. Right-click References»Add References.
  5. Select the .NET tab in the Add Reference dialog. In Visual Studio 2012, expand Assemblies»Extensions in the Add Reference dialog.
  6. Select the National Instruments assemblies required for your project with the correct version.
To refresh the WPF Design view, close the Design view and rebuild your project.