# How to edit dutsettings in code

**URL:** https://forum.opentap.io/t/how-to-edit-dutsettings-in-code/1086
**Category:** General
**Created:** [April 5, 2023, 8:17am UTC](https://forum.opentap.io/t/how-to-edit-dutsettings-in-code/1086 "2023-04-05T08:17:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![teder.ted](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@teder.ted](https://forum.opentap.io/u/teder.ted)
#### Post date: [April 5, 2023, 8:17am UTC](https://forum.opentap.io/t/how-to-edit-dutsettings-in-code/1086/1 "2023-04-05T08:17:45Z")

</div>

using

`IDut[] duts = DutSettings.Current.ToArray()`

we can have access to the list of duts. after editing the list how to save it on setting file (Settings\Bench\Defaul\DUTs.xml)?

---

<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: [April 6, 2023, 5:57am UTC](https://forum.opentap.io/t/how-to-edit-dutsettings-in-code/1086/2 "2023-04-06T05:57:18Z")

</div>

Hi @teder.ted,

Just call `DutSettings.Current.Save()`, this should save all modifications done to DutSettings.Current to the file.

If you want to verify, you can call `DutSettings.Current.Invalidate()` (or something like that. Dont remember 100%). Then call DutSettings.Current to load it again from the file.

---

<div class="post-metadata">

### Author: ![bgurdal](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@bgurdal](https://forum.opentap.io/u/bgurdal)
#### Post date: [April 6, 2023, 11:17am UTC](https://forum.opentap.io/t/how-to-edit-dutsettings-in-code/1086/3 "2023-04-06T11:17:37Z")

</div>

Hi @teder.ted ,

You may already now it, but if you want to add or remove you should use following methods. These methods must be executed by the Dispatcher thread since they are a part of the CollectionView in the Editor. I encountered a similar problem and solution is adding PresentationFramework.dll and WindowsBase.dll as reference assemblies to the project.

```csharp
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
    DutSettings.Current.Add(MyDut1); // Add IDut object
    DutSettings.Current.Remove(MyDut1); // Remove a IDut object
});

DutSettings.Current.Save(); // Save Dut Settings

```

To save the changes you can call DutSettings.Current.Save() method after editing Dut settings.

---

<div class="post-metadata">

### Author: ![teder.ted](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@teder.ted](https://forum.opentap.io/u/teder.ted)
#### Post date: [April 8, 2023, 9:44am UTC](https://forum.opentap.io/t/how-to-edit-dutsettings-in-code/1086/4 "2023-04-08T09:44:25Z")

</div>

Thanks.  
Calling

```csharp
DutSettings.Current.Save();

```

It causes this error:

> Method not found: ‘System.collections,generic.IEnumerable’1\<System.String\> OpenTap.TapSerializer.GetUsedFiles()’

also calling

` testPlan.Save()`

for saving external parameters

---

<div class="post-metadata">

### Author: ![teder.ted](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@teder.ted](https://forum.opentap.io/u/teder.ted)
#### Post date: [April 8, 2023, 10:25am UTC](https://forum.opentap.io/t/how-to-edit-dutsettings-in-code/1086/5 "2023-04-08T10:25:33Z")

</div>

I clean the project and delete all assemblies and just worked!
