views:

133

answers:

3

I'm looking for a way to avoid declaring my configuration section in the configSections inside the App.config file. Basically, I want to specify my configuration information just like I do for built-in .NET systems. For instance, when configuring WCF, I just put stuff in the <system.serviceModel>, I don't have to declare a section in the configSections up top. The same thing applies for <system.diagnostics> and many other namespaces.

I know I could just load it up as an XML file and parse through it, but I'd prefer to stick with the pattern if possible. Moreover, looking at the WCF configuration with Reflector, I notice that it uses the same configuration subsystem (defined in System.Configuration).

If you're wondering why this is important, it's because it's confusing our IT people. If it were self contained in one place, it would be much easier on them. I also realize I'll lose the ability to have multiple of the same section type, but that's not important in our case.

+2  A: 

I don't get it - you need to declare something before you can use it - even the standard .NET config sections are all declared somewhere - just not in your own app.config.

You can't "outsmart" the .NET configuration system; if you want to use configuration in the standard .NET fashion (which I'd strongly recommend - it's a known technique, it's well travelled and well tested), then you need to define your configuration sections and register them with the .NET configuration system - no way around that.

Your only option to avoid adding those sections to your app's own app.config file would be to put them into your machine.config (hidden deep in the bowels of your system - usually in the C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG directory) - check out its configuration section registrations at the top!

But quite frankly: updating those system config files on every machine using your software seems like much more of a hassle than having a few configuration sections defined in your app.config!

marc_s
OK now I know how MS does it, and you're right, putting my config sections in the machine.config isn't the answer. Thanks!
Chris Clark
A: 

You can use the AppSettings element for just this reason.

James Westgate
A: 

Really? Confuses your IT people? Okay I'll withhold comment about that...

Maybe you could just put your config info in an entirely different file, but you sort of have to reinvent the wheel.

http://www.codeproject.com/KB/files/anyconfig.aspx

JC