LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C# and LabView .Net Interop DLL: Cannot pass a GCHandle across AppDomains and System.Reflection.TargetException when calling into LabView DLL

Hi All.

 

I am wondering whether someone could help me please as I am really at a loss here. I am a seasoned C# developer and just started learning LabView to support others. Here is a background to me issue.

 

I am using a uEye camera and I intent to write some basic LabView VIs or functions, and export them as .Net Interop DLL so that I am able to use those VIs/functions in a C# application with some LabView components developed by other teams. In short, I can do simple and basic stuff but I have problems with exceptions when trying to do basic initialisation or acquire. Here are my three problems. I will start with simple ones first.

 

I am using LabView 2015 (not SP1) and VS2013 Update 5. The uEye driver is a .Net dll used in both LabView and C# and both are same version 1.6.3.0.

 

Problem 1: When a VI is outputting an array of bytes or strings as an example and that VI is exported for use in C#, how does one set the VI to output null value if the VI does not manage to perform certain task? In my head, I see indicators in LabView always outputting something. This is essentially saying if null then the method fails or output something if successful, therefore, C# can check for null.

 

 

Problem 2: In LabView, I have a VI that takes a .Net reference to uEye.Camera (already created in a different VI and initialised) and perform acquisition in the VI and it works. Next, this VI is exported as a .Net Interop DLL in which C# just calls the LabView method and passes a uEye.Camera reference to the method. This camera reference is already created and initialised.

 

The LabView VI is exported as e.g. public static void Interop.LabViewExports.CameraExample.uEye_CameraSnap_From_LabView( uEye.Camera );

 

In C# when a call is made via Interop.LabViewExports.CameraExample.uEye_CameraSnap_From_LabView( m_camera ); I get an exception below:

 

"Error msg: "Error Status set in an ErrorCluster in VI: labview_dotnet_test
uEye_CameraSnap_From_LabView.vi in the method: uEye_CameraSnap_From_LabView. ErrorCode = 1172 ErrorSource = Property Node (Arg :1) Error accessing property uEye.Camera.Display, (System.Reflection.TargetException: Object does not match target type.) [append][b]System.Reflection.TargetException[/b] in uEye_CameraSnap_From_LabView.vi->uEye_CameraSnap_From_LabView.vi.ProxyCaller"

 

I am at a lost here because in my head, I am passing a .Net reference to the VI and it should work (just same as if everything is in LabView standalone with another VI creating the .Net reference and passing to the CameraSnap VI).

 

Any idea on what is going on?

 

 

Problem 3: In LabView, I have created a VI that creates the camera to be used within LabView and it works; hurrah! Now using the same VI, I exported it as a .Net Interop DLL so that the intention is to call the VI which will create the camera and initialise it in a LabView DLL then passing the reference back in C# so I am able to access the camera for other things. The VI is exported as public static void uEye_CameraCreate( int cameraId, int colorMode, out Camera camera );

 

In C# at the point when I call the create function, it throws System.AgumentException with message "Cannot pass a GCHandle across AppDomains.\r\nParameter name: handle" and the stack trace is

 

at System.Runtime.InteropServices.GCHandle.InternalCheckDomain(IntPtr handle)
at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
at Interop.LabViewExports.CameraExample.uEye_CameraCreate(Int32 cameraId, Int32 colorMode, Camera& camera)
at LabViewGenericIdsCamera.Create() in c:\xxx\camera.cs:line xxx

 

 

Thanks peeps. Smiley Happy

 

 

 

 

 

 

Message 1 of 3
(3,390 Views)

Did you find a solution to the issues? I am also running into Problem 2: "System.Reflection.TargetException: Object does not match target type." when I use VIs in TestStand

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

No solution. We ended up using wholly C#. Think the problem was because it is to do with hardware created in CLR and passing to LVRT and LV probably has an issue with that. Hence the problem. If image capturing is wholly in C# then image data is just passed to LV as simple types then you may get that to work. However, this does not guarantee whether you will work-around it today and hit another wall a month later so using hybrid solutions are probably bad ideas unless you are doing something very specific and short lived tasks.

 

Hope it helps.

Message 3 of 3
(2,632 Views)