NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Errors passing .NET struct back to .NET

I'm trying to pass a .NET struct back into a dll so that it can do further processing.  However, if that struct contains an array, I get the 

"

An error occurred within the .NET code.
An error occurred while evaluating the expression for the element 'T1'.
All input parameters must have an expression specified.

 

An error occurred within the .NET code.An error occurred while evaluating the expression for the element 'T1'.

All input parameters must have an expression specified." error from TestStand.

 

If I try to statically define the size of the array in the .NET struct, I get

"The array for the parameter 'T1' is an input parameter and is empty.

 

 

All input parameters must have an expression specified."

 

I'm sure that the array in TestStand is not empty, as I've tried creating an array of 10, populated it with values and tried to send that. 

If it helps, T1 is an array inside the struct.  I've tried defining the struct array as [0...empty] and as a static array [0...9]

 

Any help would be appreciated.

0 Kudos
Message 1 of 13
(4,721 Views)

Hi,

 

Can you give a little more information?  Namely:

 

1) What version of TestStand are you using?

2) What else is contained in your struct besides your array?

3) What does the method you are calling look like (can you post the method prototype)?

4) I'm assuming you created a type from the struct and are passing a variable of that type in as the parameter?

 

-Jeff

0 Kudos
Message 2 of 13
(4,714 Views)

1) I'm using TestStand 4.2

2) The struct contains numerous other numbers and strings, but I've also tried creating a struct that has nothing but an array in it, the problem persists

3) The method is empty, and all it does is accept a parameter of the type of my struct

4) I have tried creating a type from the struct and passing the struct as a variable, and I've also tried creating a constructor for the struct and use the create object feature to create a .NET object and try to pass that.  Both have failed. 

0 Kudos
Message 3 of 13
(4,708 Views)

What is the type of your array inside your struct?

0 Kudos
Message 4 of 13
(4,706 Views)

It's a double array (so array of number)

0 Kudos
Message 5 of 13
(4,700 Views)

I believe there are issues when passing empty arrays in TestStand 4.2.  I got the same error as you when I created a type from a struct and then left the array empty and tried to pass it.  However, if I just changed the array to not be empty (in variables view) it worked.  You are seeing the same error even if the array is not empty?  Have you tried just declaring a non-empty array of numbers and passing it as the array element of the struct parameter?  Does this also give an error?

 

-Jeff

0 Kudos
Message 6 of 13
(4,695 Views)

Yes, I have tried creating a an array, setting it as non empty (making sure the 'Empty' checkbox is unchecked), changed the values to non-zero, and tried passing it to .NET, with no luck.

0 Kudos
Message 7 of 13
(4,675 Views)

Any chance you can provide a simple seq file and dll that reproduce this?  I believe I've tried exactly what you are describing and do not see an error.  Maybe there is some subtle difference.

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

I've attached a test sequence file with a struct

 

The class library dll it's accessing has one file, with the following code

 

 

using System;
using System.Collections.Generic;
using System.Text;
namespace ClassLibrary1
{
    public struct myStruct
    {
        double[] array;
    }
    public static class myClass
    {
        public static void TestFunction(myStruct pstruct)
        {
        }
    }
}

 

using System;

using System.Collections.Generic;

using System.Text;
namespace ClassLibrary1

{    

   public struct myStruct    

   {        

        double[] array;    

   }
   public static class myClass    

   {        

        public static void TestFunction(myStruct pstruct)        

        {
        }    

    }

}

 

Let me know if you can reproduce it with this setup and/or if I'm doing something wrong

0 Kudos
Message 9 of 13
(4,652 Views)

When I change your array to be non-empty I don't get the same error anymore.  Instead I get an error that the class info for myClass was not found.  It looks like TestStand is not finding it at runtime because it is declared as a static class.  I removed the static keyword (from just the class, not the method) and then it worked.  Let me know if this works for you and if so if it is an acceptable workaround.

0 Kudos
Message 10 of 13
(4,647 Views)