I’m using Configuration Manager to store settings in a C# application. I have some individual settings and I have a variable array of settings.
The XML Config looks something like this:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<appSettings>
<add key="Option" value="Tabbed" />
<add key="Version" value="0.0.0.0" />
<Tee1>
<add key="Name" value="Test1" />
<add key="IPAddress" value="127.0.0.1" />
<add key="Port" value="58323" />
<add key="AutoConnect" value="True" />
<add key="Link" value="False" />
<add key="Link" value="False" />
</Tee1>
<Tee2>
<add key="Name" value="Test2" />
<add key="IPAddress" value="127.0.0.1" />
<add key="Port" value="58324" />
<add key="AutoConnect" value="True" />
<add key="Link" value="False" />
<add key="Link" value="False" />
</Tee2>
<Tee3>
<add key="Name" value="Test3" />
<add key="IPAddress" value="localhost" />
<add key="Port" value="58325" />
<add key="AutoConnect" value="False" />
<add key="Link" value="True" />
<add key="Link" value="False" />
</Tee3>
<Tee4 />
<Tee5 />
<Tee6 />
<Tee7 />
<Tee8 />
<Tee9 />
<Tee10>
<add key="Name" value="Test10" />
<add key="IPAddress" value="127.0.0.1" />
<add key="Port" value="58332" />
<add key="AutoConnect" value="False" />
<add key="Link" value="False" />
<add key="Link" value="False" />
</Tee10>
</appSettings>
</configuration>
The Tee entries without data are null items.
When I load the generated XML text into the Visual Studio 2010 editor it shows TEE1 has an error.
“The element ‘appSettings’ has an invalid child element ‘Tee1’. List of possible elements expected: ‘add, remove. Clear’.”
How should I represent an array of similar items?
You can only store
key=value
settings in<appSettings>
. If you want something richer, you'll need to write a custom configuration section handler.See, for example: