From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to call InitLVClient function

Hi,

I'm trying to use LabView Interop Assembly in a .net framework 4.0 in a solution VS2010.

I known it's doesn't work with this framework.

Then i tried to make a new project ( in 3.5 ) in my solution. But it doesn't work and i can see this message : "Failed to call InitLVClient function."

I wonder why, when i create a new solution with just one project in 3.5, it works.

Can you help me ?

I don't want generate a new dll juste for that.

Thanks.

 

PS : I'm using Labview2011, VS2010, Framework 4.0 and 3.5, C#.

0 Kudos
Message 1 of 3
(2,202 Views)

Hello Seb,

 

Even though it should work with the .net 3.5 try using the workaround implemented for using labVIEW interop with the 4.0 framework:

 

call Win32's LoadLibrary function (from kernel32) prior to calling the assembly in your application. This will load the assembly twice in your .NET application, so be aware of any potential issues that may arise from that, depending on your assembly/application.

internal static class Utility
{
[DllImport("Kernel32.dll")]
static extern IntPtr GetModuleHandle(string moduleName);

[DllImport("Kernel32.dll")]
static extern IntPtr LoadLibrary(string moduleName);

internal static void ensureModuleLoaded()
{
string moduleName = System.IO.Path.GetFileName(System.Reflection.Assembly.GetAssembly(typeof(LabVIEW_Built_Assembly.Exports)).Location);

if (GetModuleHandle(moduleName) == IntPtr.Zero)
if (LoadLibrary(moduleName) == IntPtr.Zero)
throw new InvalidOperationException("Unable to load assembly.", new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()));
}

internal static void handleExceptions(VIAssemblyException e)
{
if (e.ErrorSource != null)
throw new ArgumentException(e.ErrorSource + ". Error Code: " + e.ErrorCode, e);
else if (((Exception)(e)).Message == "Invalid LV Client." || ((Exception)(e)).Message == "Failed to call InitLVClient function.")
throw new Exception("A resource dependency could not be found by your application. Check that all DLLs referenced can be found by your executable (ie. in the same folder as your executable) and that all applicable NI drivers are installed.", e);
else
throw e;
}
}

 

-----------------------------------
The attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system, or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject to the Sample Code License Terms which can be found at: http://ni.com/samplecodelicense.
-----------------------------------

 

Best regards

Romain DUVAL || RF & Semiconductor Staff System Engineer || CLA || CTA
National Instruments France

Message 2 of 3
(2,177 Views)

One more idea,

 

if you used 32-bit LV to generate the assembly and tried to call in your VC project/application (64-bit). The generated 32-bit assembly cannot load 64-bit lvrt.dll.

Romain DUVAL || RF & Semiconductor Staff System Engineer || CLA || CTA
National Instruments France

0 Kudos
Message 3 of 3
(2,174 Views)