Suppose I define a configuration section in an ASP.NET web.config like:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web">
<section name="MySettings" type="MyCompany.MyProject.Configuration.MySettings" allowLocation="true" allowDefinition="Everywhere" restartOnExternalChanges="false" />
</sectionGroup>
</configSections>
<system.web>
<MySettings knownProperty="some_value" unknownProperty="other_value" />
</system.web>
</configuration>
And suppose I define MySettings : System.Configuration.ConfigurationSection
without unknownProperty
:
using System.Configuration;
namespace MyCompany.MyProject.Configuration
{
public class MySettings : ConfigurationSection
{
public MySettings() { }
[ConfigurationProperty("knownProperty", DefaultValue="default_value")]
public string KnownProperty
{
get { return (string)this["knownProperty"]; }
}
// I'm not defining unknownProperty here on purpose
}
}
Is there anyway to run the app without getting a Configuration Error complaining about the unrecognized attribute 'unknownProperty'?
Also I'd be fine with a way to catch that error and ignore it if that's possible.
In other words, I want the XML to have an attribute that is not defined in the matching type to which it's bound. Can it be done within the confines of the existing Configuration API?