I have defined a config section in my app.config in the following way:
Having just run your code, the error I received was "The element <Company> may only appear once in this section" on the line:
RegisterCompaniesConfig serviceSection = ConfigurationManager.GetSection("RegisterCompanies") as RegisterCompaniesConfig;
That seems to indicate that you can only, with the code you've currently got, have one company element in there.
In the past I've used the following without any problems:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="Libraries">
<section name="MyLibrary" type="System.Configuration.NameValueSectionHandler,system, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null" />
</sectionGroup>
</configSections>
<Libraries>
<MyLibrary>
<add key="Test" value="Test1"/>
</MyLibrary>
</Libraries>
</configuration>
Which I've then accessed with code like:
public string GetValue(string configurationKey, string defaultValue)
{
NameValueCollection _config = (NameValueCollection)ConfigurationManager.GetSection("Libraries/MyLibrary");
string result = (_config == null) ? null : _config[configurationKey];
return (result == null ? defaultValue : result);
}
If you don't have to have attributes called "name" and "code" then you could just use the code above, otherwise you could use Reflector to get an idea of what the NameValueCollection does and work from there!