NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing a custom data type to a .NET assembly

Hello,
After struggling with an issue involving passing a complex data type to a .NET assembly from TestStand for hours, I figured I'd post and see if anyone else has any ideas.
The data type has been defined in the sequence file's custom data types.  It is (bear with me here) a container of 6 arrays of containers, each containing a unique set of string and integer variables.  Each array of containers stores one kind of configuration data for my sequence.  So I initially pass each of these 6 arrays of containers individually to 6 separate LabVIEW VIs to retrieve the appropriate info from an ini file.  That all works fine - after the 6 LabVIEW VIs run, I have one file global of this complex data type containing all the configuration info.  My next step is to pass this information to a dialog written in VB .NET.  My idea was to just pass a reference to this high-level file global to the VB .NET method.
 
So I created structures for the complex data type and for all the "sub-container" data types involved in it in the VB .NET code and activated .NET struct passing for each custom data type in TestStand, but it causes a run-time error when I attempt to run the step:  "Expected Object Reference, found Container."  In my debugging of this issue, I tried allowing TestStand to create a data type appropriate for the function argument and it created a container of 6 arrays of object references.  I'm not particularly thrilled about needing to pass object references (since that will complicate my VB .NET code forcing it to expect and deal in PropertyObjects I think), but the bigger issue is that is also complicates my LabVIEW code which was already running perfectly.  Because the arrays of config info are now arrays of object references, passing them to the LabVIEW VIs causes a different run-time error...  I suppose I could deal in PropertyObjects from LabVIEW as well, but it certainly would not be the most elegant solution I've ever seen.
 
I actually had this working when I was passing each array of containers as separate arguments to the .NET method, but I was hoping to consolidate everything into this one "master" file global containing all the info and minimize the number of arguments being passed around.
 
Anyone have any idea how I might resolve this, or if it is even possible?
Thanks!
0 Kudos
Message 1 of 4
(4,749 Views)

Hi Rob,

Sorry about the delayed reply. I have been working on this problem and I was able to replicate your issue. As such, it appears not to work correctly in TestStand currently.

I have reported the issue to our TestStand R&D team.

The workaround for the situation is, as you proposed, to pass the structs separately. While this may not be optimal for you, it is an effective solution and will get your application working again.

Matt M.
NI

0 Kudos
Message 2 of 4
(4,695 Views)

Bob,

   I've done this kind of thing in the past before. Your suspicions were correct in that you must create the complex structure in your .NET assembly before hand. You can then create a Test Stand variable of that type and pass it as a parameter to your .NET function. The only caveat is that all my stuff is done in C# so I don't really have an example in VB .NET. Nor have I ever done so with a structure quite like that which you are using. But, like I said, I've done some things that are very similar before so it still seems like what you are trying should be do-able without throwing the error you describe. 

 

Let me know if you've found a sloution. If not, maybe I'll dig out an old example to show you. Even though it is C# you still should be able to follow it.

 

0 Kudos
Message 3 of 4
(4,410 Views)

Thanks, John, for your feedback.

First let me note that I'm satisfied with passing each array of clusters as individual parameters to my .NET method - so this isn't a critical issue for me at this point.  Nevertheless, let me clarify that most of the complex data structures that I've needed to pass between TestStand and .NET code modules have worked exactly as expected.  This problem seems to specifically affect a data structure that is comprised of a cluster containing multiple arrays of different clusters.  TestStand (at least version 3.0) appears to be unable to correctly store the data type of each of the underlying clusters - so it assumes they are simply "object references".  Regardless of whether I let TestStand create the data type or whether I specifically create the data type, the problem persists.

If you have a C# example of what I have mentioned, I would be interested to see it.  (I actually prefer C# - VB .NET is simply what I am expected to use at work.)  And I don't believe the language used would affect this issue...  MSIL is MSIL.

Thanks,

Rob

0 Kudos
Message 4 of 4
(4,393 Views)