Programming with the TestStand API in C#
- Updated2025-07-23
- 3 minute(s) read
In C#, you can access the TestStand ActiveX API by adding the NationalInstruments.TestStand.Interop.API component as a reference in a project.
To add a reference to the TestStand 4.0 or later API assembly in Visual Studio, select the project in the Solution Explorer. Select Project»Add Reference to launch the Reference Manager dialog box. Click Assemblies»Extensions and select the TestStand <Version> <APIName> Interop Assembly component from the list. Click OK to close the Reference Manager dialog box. Then, expand the References node for the project in the Solution Explorer, right-click the new reference and select Properties from the context menu. In the Properties panel, change the Embed Interop Types setting to False. If this setting is True, using any constants such as PropertyOptions in your code will result in compiler errors
If the TestStand Interop assemblies do not appear in the Reference Manager dialog box, exit all running copies of Visual Studio, launch the TestStand Version Selector, select the current version of TestStand, and click the Make Active button.
After you add the NationalInstruments.TestStand.Interop.API component as a reference in a project, add the following directive at the top of the source file:
using NationalInstruments.TestStand.Interop.API;
All TestStand classes, methods, and properties are available in the Microsoft Visual Studio object browser and are accessible from the C# source code. Help text for classes, methods, and properties appears in Microsoft IntelliSense.
To control NI instruments from a .NET assembly, you must also complete the following tasks:
- Install the appropriate NI driver for the instrument you want to control. Ensure you install the correct NI .NET API for the version of the NI driver you installed. For some NI drivers, you must manually select .NET support options in the installer.
- Add a reference to the corresponding NI driver .NET API assembly to the project. The TSM Accelerometer with .NET and the Part Average Testing with .NET examples include Visual Studio projects that reference the TSM Code Module API and some NI .NET APIs and demonstrate how to invoke those APIs. Refer to the TestStand Semiconductor Module Manual for more information about these examples.
Visit ni.com/info and enter the Info Code NETAPIdriversupport for information about the available NI .NET APIs and the versions of the NI drivers each supports.
Upgrading TestStand
When you upgrade to a full, non-service pack version of TestStand and you want to continue to use existing code modules and applications in the later version, you must update the .NET assembly references in Visual Studio projects. The assemblies you build using TestStand APIs are compatible only with the version of TestStand, including service packs, you reference in Visual Studio projects.
Upgrading Instrument Drivers
When you upgrade to a later version of an instrument driver .NET API, you do not need to update the .NET assembly references in Visual Studio projects. NI instrument driver .NET API installers ensure that references to earlier versions of the instrument driver .NET API assembly are automatically redirected to the current version of the assembly if the earlier version assembly does not exist.
Related Information
- TestStand API Concepts
- TestStand Semiconductor Module Manual
- .NET Support for the TestStand API
TestStand installs .NET interop assemblies for the TestStand API in the <TestStand>\API\DotNet\Assemblies directory and in the Global Assembly Cache (GAC). The interop assemblies support the current and earlier versions of the TestStand API, as shown in the following table.