NI TestStand

Showing results for 
Search instead for 
Did you mean: 

.NET Generics and TestStand

Go to solution



I'm using the System.Collections.Generic.List<T> class, to store some stuff :).


Now when I used the .NET adapter, went to mscorlib.dll ( I can't see any of the generic classes.

The only availible item is System.Collections.Generic.KeyNotFoundException.


Why is that so?

Can't I call methods and properties on the Generics, to work directly on them?


Now I know I can cast the List<T> on the System.Collections.ICollection or the System.Collections.IList for example, to access some methods and properties, but why coulnd't I just use the List<T> class directly?




0 Kudos
Message 1 of 6

The .NET adapter does not currently support generics. You can interact with these objects using any non-generic interfaces or non-generic base classes or derived classes as you mentioned, or by writing a higher-level wrapper API around the operations that are important to you.


Adding support for generics is not as simple as just allowing the selection of the List<T> class. List<T> by itself is not a fully specified type. It would also require a way of specifying what the generic parameters (i.e. T in this case) are too. It is something that might be considered for a future version of TestStand.


Hope this helps explain things,


Message 2 of 6
Accepted by topic author Mac671

As dug9000 mentioned, this is a limitation in TestStand's .NET support that we plan to address in a future version of TestStand.


The workaround you suggest is viable, but you lose the type safety of the collection. If you want to retain the type safety of the Generic collection, you can create a concrete collection class that derives from System.Collections.Generic.IList<T>and use an internal concrete instance of List<T> to implement the interface. The C# editor can help with a lot of the boilerplate typing and if you need to do this for a lot of classes; you could create a Visual Studio code snippet to make it really fast to implement. 


Basically, you can use the following steps:

  1. Create a concrete class that derives from IList<T>. For example, public class MyTypeList : IList<MyType> {}
  2. In the Visual Studio editor, right-click on IList<MyType> in your concrete class declaration and choose Implement Interface>>Implement Interface. This will give you code shells for all of the methods and properties you need to implement.
  3. Add a private member variable, of type List<MyType> to your concrete class.
  4. In each of the interface members that Visual Studio generated for you, add the one-line call to the private member variable of type List<MyType>.


I have attached an example that shows this. It uses VS2008 and TestStand 4.2. Creating the concrete collection class took only about 5 minutes, so while this is far from ideal, it isn't terribly painful either.


David Rohacek

National Instruments



Message Edited by drohacek on 10-23-2009 10:03 AM
Message Edited by drohacek on 10-23-2009 10:03 AM
Message 3 of 6

Doug, David,


Thank you both for your feedback.


David thanks for the tip with the concrete interface implementation idea.

I did not know that function in Visual Studio, this will get me up to speed.


Thank you both,




0 Kudos
Message 4 of 6



Had the following recent thread that you might be able to answer.  Re: Using IEnumerable<string> Variables - NI Community


I reviewed your attached example.  My question is... how can you setup a variable (local, file, station) for generic (List<string>, IEnumerable<string>) to be passed into a .NET module?  Seems like you should be able to set like an Array of Strings instead of having to call another method to return the object and store in variable.  Also, is there a way to use describe in expression values?  Something like arrays ( {"one", "two" } )?


Any help is appreciated.

0 Kudos
Message 5 of 6

Answered in other thread. See other thread for details.

0 Kudos
Message 6 of 6