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: 

Convert Cluster to a .NET Object

I have a .NET dll that requires a .NET object be passed to it as a parameter.  The object is a struct that contains the following: String, .NET Object, String, String, .NET Object, String, String, String, String.  I have put all items into a cluster, converted to a varient, and then wired the varient output to the input of the Convert to .NET Object.  However I get an error every time I run my code: LabVIEW:  Cannot convert the specified LabVIEW type to  .NET object.  Method Name: .NET:Convert To .NET Type.

 

Am I able to convert a cluster to a .NET object to be passed to a .NET dll?

 

Matt

0 Kudos
Message 1 of 8
(4,690 Views)

Good Morning Matt,

 

Try removing the two .NET Objects from your cluster before using the Convert to .NET Object VI to see if the problem you are experiencing is due to trying to convert a .NET Object to a .NET Object.

0 Kudos
Message 2 of 8
(4,663 Views)

I tried your suggestion of removing the .NET objects in the cluster hower I am still getting the same error message.  Here is a screen capture of what I am doing...

 

EventLog_BlkDiagram.jpg

0 Kudos
Message 3 of 8
(4,660 Views)

Hi all,

 

Has anyone solved this issue yet or found an alternative technique?

 

Matt - did you workaround the error some how?

 

TIA

 

-Martin

Message Edited by Martin.D on 11-23-2009 06:52 PM
Message Edited by Martin.D on 11-23-2009 06:54 PM
Certified LabVIEW Architect
0 Kudos
Message 4 of 8
(4,526 Views)

I put a call in to NI and here is what they came up with...Mind you I still haven't been able to sucessfully implement it yet.

 

The reason for the error is becuase the closest equivalent to a cluster in .NET is a struct.  However, it appears that this VI does not convert the cluster into a struct.  A possible workaround for this is to create a VI like the one I have attached.  Add this VI to a project in LabVIEW 2009, and go to Build Specifications >> .NET interop assembly.  This will create an assembly (*.dll) that you should be able to call from LV.  Check out LabVIEW Help on .NET interop assemblies, too!

 

LV_Cluster_to_Struct.png

 

I am still playing with it.  I don't know if I am building the DLL wrong or what, but when I call my interop DLL my code hangs and never gets passed the method call to that LV created DLL.  If I figure it out I will post how I did it.

 

As it turns out though, one of the developers here wrote another method that built the .NET object for me.  All I needed to do was pass in all the pieces of the Struct.  His method then returned a .NET object that I coudl pass around to other .NET assemblies.

0 Kudos
Message 5 of 8
(4,519 Views)
You can't use the To .NET Object VI to convert a cluster since this is not a defined operation. There is no corresponding class to convert to - a struct isn't a class. You should, instead, use the struct's constructor and set the fields using the Property Node, or if you have a constructor where you provide all the field values you can then use that.
Message 6 of 8
(4,518 Views)

Thank you for your responses, much appreciated. For my application using the approach smercurio suggested works.

Certified LabVIEW Architect
0 Kudos
Message 7 of 8
(4,489 Views)

Hey Martin D 

 

Is it possible for you to send an example vi, I have tried the same method, but LV gives me an Access violation (0xC0000005) error when I passes the struct to a method.

 

Best regards

0 Kudos
Message 8 of 8
(3,688 Views)