Section singleton instance returns null if section within group


The section.Instance property returns null if the section is nested within groups. This is because you need to pass the path including groups to the GetSection method. E.g. for:
<myCompany xmlns="myCompany.Configuration">
    <environment name="Test1" >
      <location url="http://host.domain.com/app.html"/>
      <login enabled="true" username="user" password="password"/>
You need to call ConfigurationManager.GetSection("myCompany/Web/UITesting/environment");
For now I don't generate the singleton and just instatiate the sections myself.

file attachments


alexschrod wrote Feb 18, 2010 at 7:46 AM

Thank you for reporting this behavior. I will fix this for the next release.

demus wrote Jun 12, 2011 at 10:04 PM

Also if you used the designer to add a sectiongroup, the only places this appears is in the csd file and the sample config file (which thus gives unexplained null pointer exceptions BTW).
The sectiongroup should have an Xml Name property, and it should generate a const C# code.

andym1978 wrote Jul 8, 2011 at 1:18 PM

It was a little more difficult to perform a DIFF on this patch because there were formatting changes (spaces removed) from the source. I cleaned up the patch to better show the relevant changes and have attached the file to this post.

andym1978 wrote Jul 8, 2011 at 2:24 PM

I'm having a tough time reproducing on the 1.6x builds. Can someone create a test case that reproduces this behavior and upload the files?

wildcatter wrote Aug 1, 2011 at 8:58 PM

Evidently, this issue still affects the 2.0.0 r4 release. I tried downloading the source and applying the patched ConfigurationSectionCodeGenerator.cs, but apparently, while it does solve the nested ConfigurationSection (up to one level), the graphical designer now doesn't allow modification of any Attributes or Elements in the ConfigurationSection or modification of the Config Sections (receive an exception "The parameter is incorrect. (Exception from HRESULT:0x80070057 (E-INVALIDARG)). I'll see if I can get into the source to find the fix, but in the mean time, one can just modify the xml directly.

andym1978 wrote Aug 3, 2011 at 1:24 AM

Thanks for putting effort into this. I will try to reproduce this issue using the extra info that I've received.

RobIII wrote Jan 12, 2012 at 12:00 PM

Any progress for this issue? I discovered this awesome project recently and have immediatly started using it in my projects. This all went fine until this beast showed it's ugly head.

andym1978 wrote Feb 14, 2012 at 1:13 PM

I'm going to revisit this issue very soon. I've been pretty busy since last summer (new house, new baby, etc), but will try to devote some spare time to this.

a_pawsey wrote Nov 7, 2012 at 12:27 PM

Is there any progress on this as it has been outstanding for some time? Do you have time to deal with contributions if I make an effort to resolve this?

andym1978 wrote Dec 12, 2012 at 1:51 PM

I've added the patch to the source code repository for evaluation/testing.

doubret wrote Jun 12 at 10:17 AM

How can i download a release with this patch ?
Thanks, keep up the good work !

andym1978 wrote Sep 8 at 10:32 PM

I've integrated this patch into my local version, but the solution is not complete as only 1 level of groups is honored. For a proper fix, it must support multiple levels of grouping. I'll look at this again in the near future.

andym1978 wrote Sep 9 at 10:28 PM

I've added support for multiple-levels. Will publish after more testing.

andym1978 wrote Sep 12 at 8:11 PM

Potential Fix is checked in to TFS and in latest VS2013 package. Will close once it is deployed as download package for VS2012 and confirmed.