Invalid Library Error When Loading a DLL Written in .NET 4.0

Updated Aug 6, 2018

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base
  • LabVIEW Professional

Programming Language

  • C# .NET

Issue Details

I have created a .NET assembly using .NET 4.0. When I try to load the assembly using a .NET constructor node, I get an error message that says: 
 
The selected file is not a .NET assembly, type library, or automation executable. 
 

 
Why am I getting this error?

Solution

By default, LabVIEW 2012 SP1 and earlier supports the .NET Framework 2.0. These LabVIEW versions do not actively support the new features of .NET 3.0, 3.5, or 4.0. With the release of Visual Studio, Microsoft updated the Common Language Runtime (CLR) of the .NET Framework. If you build a .NET assembly in Visual Studio 2005 or 2008 (.NET version 3.0 and 3.5 respectively), it uses the CLR (mscorlib) version 2.0. If you build the same assembly in Visual Studio 2010 (.NET version 4.0), by default it uses the CRL version 4.0. You can verify this by using .NET Reflector.

The assembly needs to be compiled with a target framework that will be compatible with .NET 2.0. Most assemblies that do not use the new features of .NET 3.0 or 3.5 are compatible with .NET 2.0.

At the top of the new project menu bar, select .NET Framework 2.0 from the drop down menu. This allows LabVIEW to load and run the dll that you create.


Note: Alternatively, you can use a .NET configuration file to instruct LabVIEW to load a later version of the CLR. If you configure LabVIEW to load the CLR version 4.0, LabVIEW can load assemblies target to run in CLR version 4.0. However, LabVIEW has not been tested with CLR 4.0, so National Instruments recommends that you use .NET 2.0 assemblies when possible. 

WAS THIS ARTICLE HELPFUL?

Not Helpful