# Programatically Adding ChildTestStep throws exception

**URL:** <https://forum.opentap.io/t/programatically-adding-childteststep-throws-exception/870>\
**Category:** General\
**Created:** [September 26, 2022, 9:50am UTC](https://forum.opentap.io/t/programatically-adding-childteststep-throws-exception/870 "2022-09-26T09:50:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajanbabu033](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@rajanbabu033](https://forum.opentap.io/u/rajanbabu033)\
**Post date:** [September 26, 2022, 9:50am UTC](https://forum.opentap.io/t/programatically-adding-childteststep-throws-exception/870/1 "2022-09-26T09:50:44Z")

</div>

Hi Support Team,

We are planning to use OpenTAP 9.18.5. But we are facing issue when programmatically adding ChildTestSteps in the code. Kindly provide solution or suggestion. This was working fine in OpenTAP 9.10.4 version.  
This is broken in the latest release. Great to get feedback ASAP.

Example :  
///

#  
/// Constructor  
///   
public SetProgrammerDevice()  
{  
TestType = TestStepType.NonMeasurement;

```
        ChildTestSteps.Add(new SetGlobalParameter()); 
    }

```

Where,  
ChildTestSteps → TestStepList  
SetGlobalParameter → This is user defined test step derived from OpenTap.TestStep

Below is the exception Details,  
2022-09-26 17:08:43.694076 ; Main ; Error ; Caught exception while instantiating test step of type ‘SHS.SMI.ITSComponents.TestFunctions.TestSteps.SetProgrammerDevice’.  
2022-09-26 17:08:43.695826 ; Main ; Debug ; TargetInvocationException: Exception has been thrown by the target of an invocation.  
2022-09-26 17:08:43.699825 ; Main ; Debug ; at Keysight.OpenTap.Gui.TestPlanGrid.a(ITypeData A\_0, Action& A\_1)  
2022-09-26 17:08:43.699825 ; Main ; Debug ; Inner ArgumentException: Cannot add test step of type SetGlobalParameter to SetProgrammerDevice  
2022-09-26 17:08:43.699825 ; Main ; Debug ; at OpenTap.TestStepList.InsertItem(Int32 index, ITestStep item)  
2022-09-26 17:08:43.699825 ; Main ; Debug ; at System.Collections.ObjectModel.Collection`1.Add(T item)  
2022-09-26 17:08:43.699825 ; Main ; Debug ; at SHS.SMI.ITSComponents.TestFunctions.TestSteps.SetProgrammerDevice…ctor() in D:\TFS\TAP-Plugin\TAP-Plugin\_Prime\TapPlugin\Source\ITSComponents.TestFunctions\TestSteps\SetProgrammerDevice.cs:line 110  
2022-09-26 17:08:43.707136 ; Main ; Debug ; Exception caught at:  
2022-09-26 17:08:43.778905 ; Main ; Debug ; at OpenTap.ITestStep AddStepToPlan(OpenTap.ITypeData, OpenTap.ITestStepParent, Boolean)  
2022-09-26 17:08:43.778905 ; Main ; Debug ; at Void c(OpenTap.ITypeData, Boolean)  
2022-09-26 17:08:43.778905 ; Main ; Debug ; at Void c(OpenTap.ITypeData)  
2022-09-26 17:08:43.778905 ; Main ; Debug ; at Void i(System.Object, System.Windows.RoutedEventArgs)

---

<div class="post-metadata">

**Author:** ![david-wsd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/david-wsd/32/204_2.png) [@david-wsd](https://forum.opentap.io/u/david-wsd)\
**Post date:** [September 26, 2022, 9:39pm UTC](https://forum.opentap.io/t/programatically-adding-childteststep-throws-exception/870/2 "2022-09-26T21:39:37Z")

</div>

I suspect this may be the root cause:

> [@rajanbabu033](#):
>
> 2022-09-26 17:08:43.699825 ; Main ; Debug ; Inner ArgumentException: Cannot add test step of type SetGlobalParameter to SetProgrammerDevice

Do you have this attribute on the SetProgrammerDevice class?  
[AllowChildrenOfType(typeof(SetGlobalParameter))]

---

<div class="post-metadata">

**Author:** ![rajanbabu033](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@rajanbabu033](https://forum.opentap.io/u/rajanbabu033)\
**Post date:** [September 27, 2022, 1:15am UTC](https://forum.opentap.io/t/programatically-adding-childteststep-throws-exception/870/3 "2022-09-27T01:15:23Z")

</div>

Hi David,  
The solution works well. Thanks for the prompt help!

---

<div class="post-metadata">

**Author:** ![david-wsd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/david-wsd/32/204_2.png) [@david-wsd](https://forum.opentap.io/u/david-wsd)\
**Post date:** [September 28, 2022, 3:49pm UTC](https://forum.opentap.io/t/programatically-adding-childteststep-throws-exception/870/4 "2022-09-28T15:49:52Z")

</div>

Great to hear! No prob.
