Specify the Path for the .NET Assemblies Called From LabVIEW

Updated Aug 8, 2023

Reported In

Software

  • LabVIEW

Programming Language

  • C# .NET
  • Visual Basic .NET

Issue Details

I have a LabVIEW application that uses several .NET assemblies which are in different locations on the computer. I want to call those DLLs from a specific path without having to install them into the GAC or place a copy in the same folder as the LabVIEW project or built application. Is it possible to reference a .NET assembly from a specific path?

Solution

It is currently not possible to specify a .NET assembly path in LabVIEW directly since the Common Language Runtime (CLR) is responsible for locating the .NET assemblies that you call, but you can use a configuration file:
  • Create a config file for your LabVIEW project or application which must reside in the same directory as the application it configures. The following link has information on how to specify the location of the .NET DLL that you want to reference: Specifying an Assembly's Location. One requirement is that the 3rd party DLL must be strongly named. You will need to update the version using a binding redirect as LabVIEW uses the strong name (which includes the assembly's version) to find the assembly. You can find additional information in the LabVIEW Help: Specifying Which Version of a.NET Assembly to Use.
  • When you create a LabVIEW executable the referenced DLLs will be placed in the "data" in the output directory by default. If you want to test that the application is referencing the correct DLL at the referenced path in the configuration file, delete the DLL from the output "data" folder.
  • You can also apply such modifications to a LabVIEW project by naming the file <proj-name>.lvproj.config instead. But typically you will have the assemblies at a fixed location during development anyway.
  • You can get the publicKeyToken and culture specified in the config file by running the following command in PowerShell: [System.Reflection.AssemblyName]::GetAssemblyName('<path to assembly>').FullName

Additional Information

Another alternative is to use System.Reflection that can be used to load assemblies at runtime. It needs additional code for handling instance creation and method invocation. The assembly will not get listed as a dependency in LabVIEW and you will not be able to use property or invoke nodes on that assembly directly. This approach is usually not recommended unless it is necessary and when a configuration file cannot be used.