# Cannot update annotations

**URL:** <https://forum.opentap.io/t/cannot-update-annotations/675>\
**Category:** Technical\
**Created:** [May 3, 2022, 2:53pm UTC](https://forum.opentap.io/t/cannot-update-annotations/675 "2022-05-03T14:53:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphmagpie](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/ralphmagpie/32/565_2.png) [@ralphmagpie](https://forum.opentap.io/u/ralphmagpie)\
**Post date:** [May 3, 2022, 2:53pm UTC](https://forum.opentap.io/t/cannot-update-annotations/675/1 "2022-05-03T14:53:14Z")

</div>

Hi,  
I have a problem that make me crazy. I’m writing a funcion to update a teststep after editing. I use DelayStep as example. I change time from default 0,1 to 3 then serialize all parameters with a json string to my function (json is necessary for the web transmission).  
Then deserialize to a dictionary key, value; select the step in testplan by GuiId and then update all values.  
Finally I call annotations?.Write()  
If I recall the step (last row) no modification found.  
Where I’m wrong?  
Thanks in advance for help.  
Ralph

```csharp
        public void UpdateStep(string json_step) 
        {
            var dict = (Dictionary<string, object>)JsonConvert.DeserializeObject(json_step, typeof(Dictionary<string,object>));
            var id = dict["GuiId"].ToString();
            var step = testPlan.Steps.GetStep(Guid.Parse(id));
            var annotations = AnnotationCollection.Annotate(step);
            var members = annotations?.Get<IMembersAnnotation>()?.Members?.ToList();
            foreach (var x in members)
            {
                var name = x.Get<IDisplayAnnotation>().Name.ToString();
                try
                {
                    var value = dict[name];
                    x.Get<IObjectValueAnnotation>().Value = value;
                }
                catch (Exception ex)
                {

                }
            }
            annotations?.Write();
            step = testPlan.Steps.GetStep(Guid.Parse(id));
            //guiUserInterface.queryIsRunning = false;
        }

```

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [May 4, 2022, 7:44am UTC](https://forum.opentap.io/t/cannot-update-annotations/675/2 "2022-05-04T07:44:07Z")

</div>

I have two ideas:

1. There seems to be a spelling error in dict[“GuiId”]? Ah unless you mean Gui ID and not guid?

2. or maybe this:

```csharp
var value = dict[name]; // I think value is a string
 x.Get<IObjectValueAnnotation>().Value = value; // this actually expects a Double

```

Maybe you could try this:

```csharp
x.Get<INumberValueAnnotation>().Value = value; // this supports converting strings to numbers and numbers to strings.

```

---

<div class="post-metadata">

**Author:** ![ralphmagpie](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/ralphmagpie/32/565_2.png) [@ralphmagpie](https://forum.opentap.io/u/ralphmagpie)\
**Post date:** [May 4, 2022, 11:12am UTC](https://forum.opentap.io/t/cannot-update-annotations/675/3 "2022-05-04T11:12:29Z")

</div>

Thanks Rolf,

the problem was that “value” is always a string and not all members of annotations are string.  
I modified the routine of annotation update, using

m.Get().ReflectionInfo.ToString();

to have the type of members…  
How Do I cast “value” if I know datattype, directly?

The output of routine (StepDelay as example) is:

Set : Time Delay - 3 - System.Double  
Set : Verdict - NotSet - OpenTap.Verdict  
Set : Enabled - True - System.Boolean  
Set : Step Name - Delay - System.String  
Set : TypeName - Basic Steps \ Delay - System.String  
Set : Error - - System.String  
Set : Break Conditions - Inherit - OpenTap.BreakCondition  
Set : Description - Waits a user defined amount of time before continuing. - System.String

Thanks for help  
Ralph

```csharp
       public void SetAnnotations(ITestStep step, Dictionary<string, object> dict)
        {
            var annotations = AnnotationCollection.Annotate(step);
            var members = annotations?.Get<IMembersAnnotation>()?.Members.ToList();
            foreach (var m in members)
            {
                var name = m.Get<IDisplayAnnotation>().Name.ToString();
                var value = dict[name];
                var strtypedata = m.Get<IReflectionAnnotation>().ReflectionInfo.ToString();
                m.Get<IObjectValueAnnotation>().Value = value;
                Console.WriteLine($"Set : {name} - {value} - {strtypedata}");
            }
            annotations.Write();
        }

```

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [June 23, 2022, 12:29pm UTC](https://forum.opentap.io/t/cannot-update-annotations/675/4 "2022-06-23T12:29:29Z")

</div>

Sorry for not getting back to you on this.

Most things has an IStringValueAnnotation, which allows them to be read and written as strings. Maybe the best way is to use that and just let that annotation handle it.

Also, its a good idea to check that the member is writable before you try to configure it.
