NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

C# DLL struct

Solved!
Go to solution

I am trying to demonstrate how TestStand can retrieve data from a  C# DLL method returning an array of type struct.

I created a custom type in TestStand that matched the signature .NET struct but I keep running into the same error:

"No corresponding subproperty in argument 'Locals.newarray<Array Element prototype>' of type 'Row' for field '<mystring>k_BackingField of .NET struct 'TestStandObjectArray.Row'."

I have set the ".NET Struct Passing" tab to "Allow Objects of this Type to be Passed as .NET Structs".

I have also tried "Exclude when Passing Struct" on this tab as well.

I have attached my DLL, CS file, TestStand sequence, and TestStand types.ini file.

Any tips or help would be appreciated.

0 Kudos
Message 1 of 3
(4,967 Views)
Solution
Accepted by topic author tempacheer

I think I see what the problem is. You made the members of Row properties rather than fields. Instead of:

 

    public struct Row
    {
        public string mystring { get; set; }
        public bool mybool { get; set; }    
    
    }

try this:

 

    public struct Row
    {
        public string mystring;
        public bool mybool;
    
    }

 

The notation you are using "{ get; set; }", is a C# language shortcut for declaring a private field you don't care about accessing from code directly (that's why it gets named with k_BackingField) and a property to wrap it. TestStand struct passing only operates on fields, not properties.

 

Hope this helps,

-Doug

0 Kudos
Message 2 of 3
(4,947 Views)
Solution
Accepted by topic author tempacheer

Thanks for the quick response Doug!

I'm not sure that I would have figured that out because we use properties almost exclusively for public members in C# classes!

Good catch, and the error makes perfect sense now!

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