NI TestStand creates the local at run time through the property hierarchy exposed by the active SequenceContext. Convert that context with AsPropertyObject(), then call NewSubProperty(...) for an object-reference subproperty in the locals container. A C# local variable cannot substitute for this operation because it is invisible to TestStand expressions and later sequence steps.
Runtime-variable symptom
The common failure is not object creation; it is creating the reference in the wrong variable system. A reference stored only in C# belongs to the executing code module. TestStand steps cannot address it as a sequence local, display it through the sequence context, or pass it through TestStand expressions.
A TestStand local must be a named subproperty of the sequence's locals container. Its declared value type must accept an object reference. Creating only the referenced object, or retaining it only in a C# variable, leaves the required TestStand property absent.
| Approach | Visible to TestStand steps | Runtime scope | Use in this case |
|---|---|---|---|
| C# local variable | No | Code-module execution | Temporary implementation state only |
TestStand subproperty created through SequenceContext
|
Yes | Active TestStand execution context | Recommended for a dynamically created sequence local |
Property-object mechanism
SequenceContext represents the active execution context. Calling AsPropertyObject() exposes the context as a property hierarchy that can be addressed and modified through the TestStand API. NewSubProperty(...) adds a property beneath a selected container in that hierarchy.
The operation has three separate decisions: the destination, the declared TestStand value type, and the value assigned after creation. For this requirement, select the current sequence's locals container as the destination and select the object-reference value type. Creating a numeric property, as in examples for dynamic numeric variables, demonstrates the creation pattern but produces the wrong type for an object reference.
Property creation and reference assignment are also separate operations. First create the typed local. Then write the intended object reference into that property using the applicable TestStand property API. Do not move on until the property exists with the expected type; assigning through a missing path or an incompatible type turns a creation problem into a second, less obvious assignment failure.
Context and lifetime checks
Before anything else, confirm whether the variable must exist only during the current execution or must be stored permanently in the sequence file. The SequenceContext route addresses the running property hierarchy. Permanent authoring requires modifying the editable sequence-file model and saving that file; creating a runtime subproperty alone is not a file-save operation.
| Requirement | Target | Confirmation before coding |
|---|---|---|
| Current execution only | Active sequence context | Later steps in the same execution must consume the local |
| Future executions after reopening the file | Editable sequence-file definition | The modified file must be saved and reopened for verification |
Next, confirm that the supplied context belongs to the sequence whose local scope must receive the property. A valid context from a different execution level can expose a valid property object while still targeting the wrong scope. Also confirm that the requested name is not already present. Decide explicitly whether an existing property is an error, should be reused after a type check, or should be replaced through a controlled authoring operation.
C# creation procedure
Receive the active
SequenceContextin the C# code module. Reject a missing or stale context before attempting any property operation.-
Convert the context to its property-object view:
SequenceContext.AsPropertyObject()Confirm that the conversion returns the property hierarchy associated with the intended execution.
Construct the destination beneath the sequence's locals container. Validate the variable name before combining it with the destination path; separators or malformed path text can redirect the operation or make the path invalid.
-
Call the creation method on the converted property object:
SequenceContext.AsPropertyObject().NewSubProperty(...)In the installed TestStand Help, open the entry for
NewSubPropertyand select the overload and parameter values for the installed API version. Set the destination path, object-reference value type, and creation options deliberately. Do not copy the numeric type from a dynamic numeric-variable example. Read the new property back from the same context. Confirm its path, scope, and declared type before assigning a reference.
Assign the intended object to the new property through the TestStand property API. Read it back and compare its identity or a known member with the source object.
Failure isolation
| Observed result | Likely cause | Diagnostic action |
|---|---|---|
| Later step reports that the local is missing | The property was created under the wrong context or container | Inspect the active context immediately after NewSubProperty(...) and read the property by its intended destination |
| Creation reports that the property already exists | The code runs more than once or the local was predefined | Check for the property first and apply the chosen reuse-or-error policy |
| Reference assignment fails | The new property has the wrong declared type | Inspect its type and recreate it as an object-reference property when appropriate |
| The property disappears in a later run | Only the runtime context was modified | Use the editable sequence-file model and save when persistence is required |
| The property exists but contains no usable object | Creation succeeded, but assignment failed or the referenced object ended its lifetime | Read the reference immediately after assignment and again at the consuming step |
Separate API errors into conversion, creation, lookup, and assignment stages. Record the exact failing stage and the property destination. A single combined block that creates and assigns without an intermediate readback hides whether the local was never created, was created in the wrong scope, or rejected the assigned reference.
Execution verification
Run the code module once and inspect the current sequence locals immediately after the creation call. Confirm that exactly one new property appears in the intended local scope.
Read the property's declared type through the same context. Do not move on until it is an object-reference type rather than the numeric type used by the example pattern.
Assign a known object, then consume the local from a later TestStand step. Verify a known member or identity characteristic rather than checking only that the property name exists.
Run the creation path a second time. Confirm that the selected duplicate-name policy produces a controlled result instead of creating an unexpected property or failing downstream.
If persistence is required, save the edited sequence file, close it, reopen it, and verify that the local definition remains present before starting another execution.
FAQ
What happens if I keep the object reference only in a C# local?
The reference remains code-module state and is not a TestStand sequence local. Create the TestStand property through SequenceContext.AsPropertyObject().NewSubProperty(...) when later steps must address it.
What happens if NewSubProperty creates a numeric variable?
The destination logic may be correct, but the declared value type is wrong for an object reference. Select the object-reference type documented for NewSubProperty in the installed TestStand Help, recreate the property, and verify its type before assignment.
What happens if the new local disappears after execution?
The runtime context was modified without persisting the sequence-file definition. For a permanent local, edit and save the sequence file, reopen it, and perform the final check that the object-reference local remains defined.