Working with 64-bit .NET Support for NI-DAQmx

NI-DAQmx 17.1 .NET Class Library Help

Edition Date: June 2017

Part Number: 370473J-01

»View Product Info
Download Help (Windows Only)

You can use the NI-DAQmx .NET platform-specific assembly for the 64-bit (x64) platform to create 64-bit NI-DAQmx applications. This assembly, NationalInstruments.DAQmx.dll , is located in the Program Files\National Instruments\<Product Name>\DotNET\Assemblies (64-bit)\Current directory.

The assembly name for the 64-bit platform-specific assembly is the same as the assembly name for the 32-bit platform-specific assembly, NationalInstruments.DAQmx.dll, and the location for the 32-bit (x86) platform-specific assembly is located in the Program Files\National Instruments\ProductName\DotNET\Assemblies\Current directory.

Note Note   Reading and writing with the NI-DAQmx .NET class library uses the same entry points for both the x86 and the x64 versions of the platform-specific assemblies because of the array size limitation in the .NET Framework.

Not all NI DAQ hardware supported by NI-DAQmx is supported in 64-bit user mode. Refer to the NI-DAQ Readme for more information, installed at Start»All Programs»National Instruments»NI-DAQ»NI-DAQ Readme.

Processor Architectures and the .NET CLR

The .NET Framework, versions 2.0 and later, includes different versions of the Common Language Runtime (CLR) for different processor architectures. Processor architectures supported by the CLR include x86, Itanium, and x64. x86 is a 32-bit architecture, while Itanium and x64 are 64-bit architectures.

Different variants of Windows operating systems exist to support different architectures. For example, Windows Vista 32-bit supports the x86 architecture and Windows Vista 64-bit supports the x64 architecture. Additionally, the x64 architecture supports the x86 instruction set, allowing 64-bit versions of Windows to include the WOW64 emulator. Consequently, both the 32-bit x86 version of the CLR and the 64-bit x64 version of the CLR can run on 64-bit versions of Windows. Applications that run under the x86 version of the CLR are 32-bit applications. Applications that run under the 64-bit version of the CLR are 64-bit applications. 64-bit applications cannot load 32-bit assemblies, and 32-bit applications cannot load 64-bit assemblies.

Platform-Specific and Platform-Agnostic Assemblies

Every assembly built for the.NET Framework 2.0 and later specifies a target platform. The target platform indicates whether the assembly can be run with the 32-bit, x86 version of the CLR or the 64-bit, x64 version of the CLR. Target platforms supported by NI assemblies include x86, x64, and AnyCPU.

The x86 target platform indicates that the assembly is compiled for and can be run only under the 32-bit, x86 version of the CLR. The x64 target platform indicates that the assembly is compiled for and can be run only under the 64-bit, x64 version of the CLR. The AnyCPU target platform indicates that the assembly is compiled in a manner that allows it to be run under any version of the CLR. Assemblies with target platform set to x86 or x64 are referred to as platform-specific assemblies. Assemblies with target platform set to AnyCPU are referred to as platform-agnostic assemblies.

The following table summarizes the preceding information:

Assembly Target Platform Compilers Operating Systems CLR Versions Assembly Type
x86 Visual C#, Visual Basic .NET 32-bit, 64-bit x86 Platform-Specific
x64 Visual C#, Visual Basic .NET 64-bit x64 Platform-Specific
AnyCPU Visual C#, Visual Basic .NET 32-bit, 64-bit x86, x64 Platform-Agnostic

The following example demonstrates how platform-specific and platform-agnostic assemblies are used in platform-specific and platform-agnostic applications.

If you have the following three assemblies:

Assembly Name Target Platform
Assembly1_AnyCPU.dll Any CPU (AnyCPU in Visual Basic)
Assembly2_x86.dll x86
Assembly3_x64.dll x64

And the following three applications:

Application Name Target Platform
Application1_AnyCPU.exe Any CPU (AnyCPU in Visual Basic)
Application2_x86.exe x86
Application3_x64.exe x64
Running these applications on a 32-bit operating system has the following results:
  1. Application1_AnyCPU.exe runs as a 32-bit process. The application can load Assembly1_AnyCPU.dll and Assembly2_x86.dll, because these assemblies are Any CPU and x86 assemblies, respectively. The application generates a BadImageFormatException if it tries to load Assembly3_x64.dll , because an x64 assembly cannot be loaded into a 32-bit process.
  2. Application2_x86.exe runs as a 32-bit process. The application can load Assembly1_AnyCPU.dll and Assembly2_x86.dll, because these assemblies are Any CPU and x86 DLLs, respectively. The application generates a BadImageFormatException if it tries to load Assembly3_x64.dll, because an x64 assembly cannot be loaded into a 32-bit process.
  3. Application3_x64.exe does not run because a 32-bit operating system cannot run a 64-bit application.
In comparison, running these executables on a 64-bit operating system has the following results:
  1. Application1_AnyCPU.exe runs as a 64-bit process. The application can load Assembly1_AnyCPU.dll and Assembly3_x64.dll, because these assemblies are Any CPU and x64, respectively. The application generates a BadImageFormatException when it tries to load Assembly2_x86.dll, because an x86 assembly cannot be loaded into a 64-bit process.
  2. Application2_x86.exe runs as a 32-bit process, under the WOW64 emulator. The application can load Assembly1_AnyCPU.dll and Assembly2_x86.dll, because these assemblies are Any CPU and x86, respectively. The application generates a BadImageFormatException when it tries to load Assembly3_x64.dll, because an x64 assembly cannot be loaded into a 32-bit process.
  3. Application3_x64.exe runs as a 64-bit process. The application can load Assembly1_AnyCPU.dll and Assembly3_x64.dll, because these assemblies are Any CPU and x64, respectively. The application generates a BadImageFormatException when it tries to load Assembly2_x86.dll, because an x86 assembly cannot be loaded into a 64-bit process.

Platform-Specific Assembly Runtime Reference Resolution

When you run a platform-agnostic or x64 platform-specific application on a 64-bit operating system and your application references a platform-specific assembly, the CLR automatically uses the x64 assembly, even if the project used to build the application references an x86 version of a platform-specific assembly.

Note Note   If the CLR attempts to load the 64-bit assembly and cannot find it, the CLR will attempt to load the x86 assembly instead, causing the CLR to generate a BadImageFormatException.

Platform-Specific and Platform-Agnostic Assemblies

Some NI class libraries include platform-specific assemblies and some include platform-agnostic assemblies. Class libraries, such as the NI-DAQmx .NET library, that include platform-specific assemblies include two versions of the assembly, one that supports the x86 platform and one that supports the x64 platform. Both versions of the assembly have the same name, but they are installed to different locations:

  • NI .NET x86 and Any CPU assemblies are, by default, installed in the Program Files(x86)\National Instruments\<Product Name>\DotNET\Assemblies\Current directory.
  • NI .NET x64 assemblies are, by default, installed in the Program Files(x86)\National Instruments\<Product Name>\DotNET\Assemblies (64-bit)\Current directory.

Using a 32-bit Assembly in a 64-bit Project

When you compile a project with target platform set to x64 with a reference to an x86 assembly, the compiler generates a warning. Change the project target platform to x86 or AnyCPU to resolve this warning.

  • The Visual C# compiler warning is: Warning CS1607 Assembly generation -- Referenced assembly targets a different processor. Refer to Warning CS1607 for more information.
  • The Visual Basic .NET compiler warning is: Warning BC40010: Possible problem detected while building assembly '<assemblyname>'. Refer to Warning BC40010 for more information.
Tip Tip   If your project references any class libraries that do not have 64-bit support, such as the DataSocket .NET class library or NI-DAQmx .NET class libraries prior to version 8.9.5, then the target platform for the project must be x86.

.NET Framework Array Size Limitation

The .NET Framework 4.0 CLR (both 32-bit and 64-bit versions) and earlier versions limit the maximum size of a single object, including arrays, to 2 gigabytes (GB). As a result of this 2 GB maximum, the number of items that an array can contain depends on the type and what the type contains.

As a consequence of this array size limitation, NI .NET arrays cannot return the same number of items as the corresponding C API can in an unmanaged layer, as unmanaged 64-bit applications can reference blocks of memory larger than 2 GB.

These restrictions typically affect input and output operations. For example, the NI-DAQmx .NET class library restricts the number of samples you can obtain in each read operation.

In .NET Framework 4.5, you can use the <gcAllowVeryLargeObjects> element to enable arrays that are greater than 2 gigabytes (GB) in total size. NI .NET class libraries do not support arrays greater than 2 GB in size; therefore, using arrays greater than 2 GB in NI .NET class libraries could result in errors or unexpected behavior.

Deploying 64-bit Applications

To facilitate use in Visual Studio Setup projects, all NI .NET class libraries that support 64-bit include both 32-bit and 64-bit deployment merge modules. This is true regardless of whether the class library includes platform-specific or platform-agnostic assemblies.

WAS THIS ARTICLE HELPFUL?

Not Helpful