If I have a configuration file with the following list of values in the configuration.
The configuration file is an xml file...
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<Employees foor="bar">
<Employee name="aaa" surname="bbb"/>
<Employee name="ddd" surname="eee"/>
<Employee name="fff" surname="ggg"/>
</Employees>
</configuration>
Using Microsoft.Extensions.Configuration
, I try to load the xml as follow
public class Employee
{
public string Name{get;set;}
public string Surname{get;set;}
}
...
public class Employees
{
public List<Employee> Employees{ get; set;}
public string Foo {get; set; }
}
...
var configurationBuilder = new ConfigurationBuilder()
AddXmlFile(path: "\\MyConfig.config")
.Build();
var employees = configurationBuilder.GetSection("Employees").Get<Employees>()
...
But the list returned is null, I am able to read single values if I move them up one level, but I would like to read a list of values inside my list.
It also does not work if I have a class within a class
For example
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<Outer foor="bar">
<Inner name="aaa" surname="bbb"/>
</Outer>
</configuration>