Error Loading .NET Assemblies in LabVIEW

Updated Nov 23, 2018

Reported In

Software

  • LabVIEW

Operating System

  • Windows

Other

.NET Assemblies

Issue Details

When I try to load .NET assemblies in LabVIEW, I receive one of the following error messages:

An error occurred trying to load the assembly



The version of the assembly you requested was automatically promoted to a later version by the .NET runtime engine.

Solution

LabVIEW 2013 uses .NET 4.0 by default, later versions of LabVIEW use more recent versions of the .NET framework by default. When loading an assembly targeted to any earlier versions of the .NET Framework, LabVIEW will automatically promote the assembly to the later version.
 

With .NET 4.0, a new security model was introduced. This new security model automatically grants full trust to locally available assemblies, but not to assemblies obtained from remote sources like the Internet, network locations, or via email. In case LabVIEW tries to access such an assembly's dll file with missing trust and is thus denied access, LabVIEW will return an error:  An error occurred trying to load the assembly.
Please note: This error message may also occur when you attempt to load a 64-bit .NET dll into a 32-bit version of LabVIEW or vice-versa.

There are two ways to grant assemblies from remote sources full trust. Either by generally allowing LabVIEW to access these through a token in a .NET configuration file, or by allowing individual assemblies manually.


.NET configuration file
Follow these steps to allow LabVIEW access to all .NET assembly. Please note that this approach imposes a potential security risk.

  1. Use a text editor to create a file that contains the following text: 
    <?xml version ="1.0"?>
    <configuration>
      <runtime>
        <loadFromRemoteSources enabled="true" />
      </runtime>
    </configuration>

     
  2. Save this file as LabVIEW.exe.config to trust all assemblies loaded into LabVIEW, or see Configuring a .NET Client Application - LabVIEW 2017 Help for more information on how to apply configuration files to LabVIEW Project files, shared libraries, or stand-alone executables. Please not that such a reduced scope lowers the potential security risk by generally allowing remote assemblies to be loaded.
  3. Place the file created in the previous step in the same directory as the file it was created for: E.g. a LabVIEW.exe.config file in the same directory as the LabVIEW.exe file, which is typically located in C:\Program Files (x86)\National Instruments\LabVIEW 2018\.


Granting access rights manually
The following is only possible in Windows 7 and later. After LabVIEW has failed loading an assembly, Windows adds an option to unblock the assembly on the file's properties:


Check Unblock and click OK to grant an assembly full trust.

Additional Information

For information about loading .NET 2.0, 3.0, or 3.5 assemblies, please refer to Loading .NET 2.0, 3.0, and 3.5 Assemblies in LabVIEW - LabVIEW 2017 Help. Please note that when using .NET assemblies it is suggested to use a LabVIEW project rather than a stand-alone VI, .
 

Note: When using any virtualization solution like Parallels Desktop, VMWare Fusion, or Oracle VirtualBox to run Windows inside a virtual machine, the new security model treats the shared directories (e.g. folders that begin with /psf or \\vmware-host\) as remote sources, as these are accessed through a network link. You need to grant assemblies in these directories full trust as well.

WAS THIS ARTICLE HELPFUL?

Not Helpful