Loader Lock Error When Calling NI-DAQmx 21.0 Using .NET

Updated Dec 18, 2023

Reported In

Driver

  • NI-DAQmx 21.0

Programming Language

  • C# .NET
  • Visual Basic .NET

Other

Visual Studio

Issue Details

I opened one of the NI-DAQmx .NET examples using Visual Studio and when running the project I get the following exception message:

"Managed Debugging Assistant 'LoaderLock': 'DLL'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\NationalInstruments.DAQmx\v4.0_21.0.45.49311__4febd62461bf11a4\NationalInstruments.DAQmx.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang."

The error message should look similar to the one below:
 
exception.png
 
Any .NET application that calls the NI-DAQmx 21.0 .NET API will crash on launch showing an error message similar to this one: "System.IO.FileLoadException : Could not load file or assembly 'NationalInstruments.DAQmx.dll' or one of its dependencies. A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)"

Solution

This is a known issue with the NI-DAQmx 21.0 NET API that will cause a Loader Lock exception to be thrown when running a project that uses the NI-DAQmx .NET API. This bug will also cause any executable that uses the .NET API to crash saying one of the dependencies cannot be loaded, even if it was built against a different version of the driver. The bug with ID 1579056 (The NI-DAQmx .NET application crashes on launch with version 21.0) was fixed in the NI-DAQmx 21.3 release. 

Additional Information

There is currently no known workaround for the issue, you need to upgrade to NI-DAQmx 21.3 or install an earlier version than 21.0.