configSource doesn't work in system.serviceModel *or* its subsections
Solution 1
VS.NET's editor moans about the config, but it works.
I have config like this...
<system.serviceModel>
<behaviors configSource="config\system.servicemodel.behaviors.config" />
<bindings configSource="config\system.servicemodel.bindings.config" />
<client configSource="config\system.servicemodel.client.config" />
</system.serviceModel>
... which works fine.
Solution 2
It will NOT work on <system.serviceModel>
since that's a configuration SectionGroup - not a configuration Section.
It WILL work just fine at runtime on anything below <system.serviceModel>
- we do this all the time. Martin's answer shows it nicely - his sample will work.
Solution 3
One thing to be aware of when moving your config sections to separate files: make sure your separated config file does NOT contain a configSource attribute. For example, if you split your your bindings section out like so,
<system.serviceModel>
<bindings configSource="yourConfigFile.config" />
</system.serviceModel>
make sure that your actual bindings file doesn't contain the "configSource" attribute:
<?xml version="1.0" encoding="utf-8"?>
<bindings>
<!-- binding configuration stuff -->
</bindings>
I know that might seem obvious, but if you enter the configSource attribute, then cut and paste into a new file, it's easy to forget to take the attribute out.
Hope this helps.
andriy
A .NET developer in the Germany/France/Switzerland border area. I do web development, desktop development, Selenium automation, and lots more. Currently employed at Dreamlines GmbH. I can help you transition your team to Git automate your regression tests release your next great ASP.NET MVC, WPF, or even WinForms app chase down those hard-to-catch bugs write tests for things that are hard to test I speak fluent English, excellent Romanian, and pretty good German. And a smattering of French, at least enough to tell the airport taxi drivers how to find my house.
Updated on June 25, 2022Comments
-
andriy almost 2 years
I'm trying to split an app.config file into multiple files to make it easier to manage the differences needed for different environments. With some sections it was easy...
<system.diagnostics> various stuff </system.diagnostics>
became
<system.diagnostics configSource="ConfigFiles\system.diagnostics.dev" />
with the "various stuff" moved to the system.diagnostics.dev file.
But for the
system.serviceModel
section this doesn't seem to work.Now I've read suggestions that it doesn't work for
system.serviceModel
itself, but it works for the sections underneath it:bindings
,client
,diagnostics
, etc. But the same thing happens to me when I try to use configSource with one of them. When I put in<system.serviceModel> <bindings configSource="ConfigFiles\whateverFile.dev" />
I get:
The 'configSource' attribute is not declared.
Has anyone else seen this? Do you know a solution? (Perhaps I have an out-of-date schema or something?)
-
andriy about 15 yearsIf it WILL work on anything below <system.serviceModel>, then why DOESN'T IT work on anything below <system.serviceModel>? I've read in a dozen places that it "will" work. But it doesn't. Hence the question.
-
marc_s about 15 yearsNo, I'm saying there's something odd happening here, since "it works on my machine" :-) What version of .NET are you using?
-
andriy about 15 yearsYep, you're right. I see now that it complains when editing the config, but when you run the app, it actually works.
-
marc_s about 15 yearsAh, I see - it does work after all. Hate to say: I said so :-)
-
Adam Pope over 12 yearsI've just been playing with this and discovered that configSource works on the
<client>
element but not an individual<endpoint>
element. -
granadaCoder about 10 yearsextensions and services also works : <behaviors configSource="WCFBehaviors.config"> </behaviors> <extensions configSource="WCFExtensions.config"> </extensions> <bindings configSource="WCFBindings.config"> </bindings> <client configSource="WCFClient.config"> </client> <services configSource="WCFServices.config"> </services>
-
Andrea Scarcella over 9 yearsLate to the party and aware of it, but I had to set 'Copy to output directory' to 'Copy always' for each config file to get the accepted solution to work. Hope it helps.
-
realbart almost 6 yearsDoes anybody know how to suppress the warnings "The 'configsource' attribute is not allowed.