Calling .NET 4.0 Code Modules with TestStand and Visual Studio 2010

Updated Apr 24, 2023

Reported In

Software

  • TestStand
  • TestStand 2010
  • TestStand 4.0
  • Measurement Studio (Legacy)

Issue Details

Can I call .NET 4.0 assemblies or VC++ DLLs built in Visual Studio from TestStand, and can I use TestStand features like Create/Edit Code and debugging with Visual Studio?

Solution

Support for .NET 4.0 and Visual Studio 2010 depends on the TestStand version you are using. Refer to the sections below for information pertaining to your TestStand version.

TestStand 2012 and Later - Native Support
As of TestStand 2012, the .NET adapter can natively call and debug any .NET 4.0 assemblies built using Visual Studio 2010.

TestStand 2010 and 2010 SP1 - Support using a configuration file
The TestStand 2010 and 2010 SP1 .NET adapter can call .NET Framework 4.0 assemblies created in Visual Studio 2010 through the use of a configuration file. Please see the Using the .NET Framework section in Chapter 5 of the TestStand Reference Manual  for specific information on creating such a configuration file.

TestStand 4.2.1 and Earlier - Not fully supported
The TestStand 4.2.1 and earlier .NET adapter does not support calling .NET Framework 4.0 assemblies. However, National Instruments has performed limited testing with TestStand 4.2.1. A summary of the results of this testing is provided below.



 

Additional Information

TestStand 2012 and Later
 TestStand 2012 is built against the .NET 4.0 Common Language Runtime (CLR), and therefore supports assemblies built using .NET 4.0 or earlier.

Note: By default, an application that uses the .NET CLR 4.0 cannot load an assembly written in C++/CLI and built against an earlier .NET Framework version. In order to use these assemblies, you must create a configuration file.  Refer to the document TestStand 2012 Help: New Features - .NET Support Enhancements for specific information on creating such a configuration file.

TestStand 2010 and 2010 SP1
 .NET 4.0 is not natively supported in TestStand 2010 SP1 and previous because it is built against the .NET 2.0 CLR, and the 2.0 CLR versions (which is used by .NET 3.5 and earlier) do not support concurrent use of the the .NET 4.0 CLR.

In order to use .NET 4.0 assemblies, the .NET 4.0 CLR, instead of the 2.0 version, must be loaded by the TestStand application, which is accomplished through the use of a configuration file.

TestStand 2010 and later supports using features like Create/Edit Code, debugging, and calling .NET assemblies or VC++ DLLs with Visual Studio 2010.

TestStand 4.2.1 and Earlier
TestStand 4.2.1 and earlier versions do not officially support features like Create/Edit Code, debugging, and calling .NET assemblies or Visual C++ DLLs with Visual Studio 2010.

Features that worked successfully in limited testing:
  1. Call assemblies built in Visual Studio 2010 that target .NET Framework 2.0, 3.0, or 3.5
  2. Call unmanaged C/C++ DLLs built in Visual Studio 2010
  3. Use the Edit Code feature for C#.NET and VB.NET projects
  4. Debug your code modules using Visual Studio 2010
  5. Use TestStand UI Controls in Visual Studio 2010
Features that did not work successfully in limited testing:
  1. Call assemblies built in Visual Studio 2010 that target .NET Framework 4.0
  2. Use the Create Code feature for any Visual Studio 2010 projects
  3. Use the Edit Code feature for any VC++ Visual Studio 2010 projects
  4. Use the TestStand Step Into feature to debug your code modules with Visual Studio 2010

The information below provides additional details on these results.

Using the .NET Adapter to call .NET Assemblies built in Visual Studio 2010
When you install Visual Studio 2010, you will also install .NET Framework 4.0, which uses a newer version of the Common Language Runtime (CLR) than .NET Framework 2.0, 3.0, and 3.5 (.NET Framework 2.0, 3.0, and 3.5 all use the same CLR version). TestStand 4.2.1 and earlier versions load the .NET Framework 2.0, and do not support loading the .NET Framework 4.0, so calling .NET Framework 4.0 assemblies in TestStand 4.2.1 and earlier versions is not supported.

Similar to previous versions of Visual Studio, Visual Studio 2010 allows the user to target a specific version of the .NET Framework to build the assembly against. Thus, you can still use Visual Studio 2010 to build your assemblies so long as you target them for .NET Framework 2.0, 3.0 or 3.5. For instructions on how to change the target framework version, see the How to: Target a Specific .NET Framework Version or Profile MSDN article.

If you open an old .NET project in Visual Studio 2010, the conversion process will automatically configure the converted project to maintain the original target framework version of the old project. For example, if you open a Visual Studio 2005 solution/project in Visual Studio 2010, the converted project will specify .NET Framework 2.0 in the Target framework combo box.

For new .NET projects,  you can specify the target framework version at the time of project creation as shown below:

Using the .NET Adapter to call VC++ CLR Assemblies built in Visual Studio 2010
Similar to the .NET assembly scenario described above, calling .NET Framework 4.0 C++ CLR assemblies in TestStand 4.2.1 and earlier versions is not supported. Thus, C++ CLR DLLs must also be configured to target .NET Framework 2.0, 3.0, or 3.5. Unlike .NET projects, if you open an old CLR project in Visual Studio 2010, the conversion process will automatically configure the converted project to target .NET Framework 4.0. Additionally, Visual Studio 2010 does not support retargeting existing C++ applications from within the IDE.

When you open an old C++ project in Visual Studio 2010, the conversion process will create a new project file in the new .vcxproj file format which you can edit to specify a different target framework version.

Similar to .NET Projects, you can specify the target framework version for new C++ CLR projects at the time of project creation as shown below:

Using the C/C++ Adapter to call Unmanaged VC++ DLLs built in Visual Studio 2010
For the Create/Edit Code feature, TestStand 4.2.1 requires that Measurement Studio be installed. Measurement Studio 2009 and previous versions do not support and cannot integrate with Visual Studio 2010. If you have a previous version of Visual Studio installed, and have installed Measurement Studio for that version of Visual Studio, then you will still be allowed to attempt to use the Create/Edit Code feature with Visual Studio 2010.

Create/Edit Code
The Create Code feature is not supported with any type of Visual Studio 2010 project in TestStand 4.2.1.

Using Edit Code with Visual Studio 2010 C#.NET and VB.NET projects in TestStand 4.2.1 should work and behave the same as with Visual Studio 2008 and prior C#.NET and VB.NET projects.  

Using Edit Code with any type of Visual Studio 2010 C++ project in TestStand 4.2.1 is not supported. Visual Studio 2010 introduced a new file format for C++ projects (.vcxproj) that TestStand 4.2.1 versions do not support.

Debugging Visual Studio 2010 Code Modules
The TestStand 4.2.1 Step Into feature is not supported with Visual Studio 2010. If you attempt to Step Into a .NET or C/C++ code module using Visual Studio 2010, you will receive an error similar to the one below:

With TestStand already open, launch your C#.NET, VB.NET, or C++ CLR project in Visual Studio 2010.  Select Debug»Attach to Process... (you can also select Tools»Attach to Process...). In the Attach to Process window, find the instance of the TestStand 4.2.1 process you are running (e.g. Sequence Editor would be SeqEdit.exe, default shipping UI would be TestExec.exe) and select it. Click the Select... button in the Attach to field. In the Select Code Type, you must ensure that you have selected Managed (v2.0, v1.1, v1.0).

Click OK in the Select Code Type window and then click Attach in the Attach to Process window.  Finally, place a breakpoint in your code at the location you want to start debugging and run your TestStand 4.2.1 sequence.  Visual Studio will automatically pause at the breakpoint when TestStand calls that piece of code.  You can then use the Visual Studio debugging tools to debug your code modules before stepping out to TestStand and continuing the execution.

Using the C/C++ Adapter to debug Unmanaged C++ code modules
To debug unmanaged C++ code modules, follow the same procedure  provided in the Using the .NET Adapter to debug .NET Framework 2.0, 3.0, or 3.5 code modules section of this document, but select Native in the Select Code Type window.

The TestStand 4.2.1 Version Selector successfully installs the TestStand toolbox to Visual Studio 2010.  Thus, when you open a C#.NET or VB.NET project that contains a Windows Form, the Toolbox will already have the TestStand UI controls available for you to use.

Visual Studio 2010 uses a new mechanism for storing VC++ include paths.  Therefore, the TestStand 4.2.1 Version Selector does not install the VC++ include paths to Visual Studio 2010.
Calling unmanaged VC++ code modules built in Visual Studio 2010 using the TestStand 4.2.1 C/C++ Adapter should work and behave the same as Visual Studio 2008 and prior VC++ code modules.


Version Selector
In order to debug your code modules in Visual Studio 2010, you will have to open Visual Studio 2010 and attach to the TestStand 4.2.1 process.