Reference to DLL Could Not Be Added When Calling LabVIEW-Built DLL From C# Code

Updated Aug 21, 2024

Reported In

Software

  • LabVIEW

Programming Language

  • C# .NET
  • Visual Basic .NET

Other

  • Visual Studio

Issue Details

I created a program in LabVIEW that is using USB-8452 to communicate with an I2C device. Then, I generated a shared library (.dll) using LabVIEW Application Builder. However, I am encountering an error when trying to call this DLL in the C#.NET environment.
The error message is:
"A reference to '~.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component."

I want to call the DLL created on PC B (LabVIEW development PC) in PC A (C# development PC). The environment is as follows.

PC A: Microsoft Visual Studio Express 2017
PC B: LabVIEW 2021 SP1 32bit

LabVIEW Runtime and USB-845x driver are already installed on PC A.

Solution

If you are using .NET programming language to integrate LabVIEW-built shared library, it is highly recommended to build a .NET Interop Assembly DLL instead of Shared Library DLL.
.NET Interop Assembly is using .NET framework which is compatible with .NET programming language such as C# or Visual Basic.

Additional Information

If you need to call Shared Library (DLL) from .NET programming language, refer to How Do I Use a LabVIEW-Built Shared Library in a .NET Project? article.