09-05-2012 08:46 AM
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#.
09-06-2012 07:31 AM
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
09-06-2012 07:37 AM
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