This project has moved and is read-only. For the latest updates, please go here.


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=""/>
      <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 8:46 AM

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

wrote May 9, 2011 at 5:29 PM

wrote Jun 12, 2011 at 10:59 PM

demus wrote Jun 12, 2011 at 11: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.

wrote Jul 8, 2011 at 2:18 PM

andym1978 wrote Jul 8, 2011 at 2: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 3: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?

wrote Jul 26, 2011 at 3:37 PM

wrote Aug 1, 2011 at 9:44 PM

wildcatter wrote Aug 1, 2011 at 9: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 2:24 AM

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

wrote Jan 12, 2012 at 12:57 PM

RobIII wrote Jan 12, 2012 at 1: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 2: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 1: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?

wrote Nov 9, 2012 at 2:23 PM

andym1978 wrote Dec 12, 2012 at 2:51 PM

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

wrote Feb 22, 2013 at 12:30 AM

doubret wrote Jun 12, 2014 at 11:17 AM

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

andym1978 wrote Sep 8, 2014 at 11: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, 2014 at 11:28 PM

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

andym1978 wrote Sep 12, 2014 at 9: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.

wrote Sep 12, 2014 at 9:11 PM

simone86 wrote Mar 6, 2015 at 12:29 PM

Still have this problem... I am working on VS2013 Premium and CSD

If I put my section inside a Group I receive null when I try to execute following line
Configs.MySettingsSection.Instance //<- Instance is null;
If I remove group everything works...

Here how I have tried:
<sectionGroup name="mySectionGroup " type="Configs.MediaCommunications">
      <section name="settings" type="Configs.Settings, Website" allowLocation="true" allowDefinition="Everywhere" />
or in this way:
<sectionGroup name="mySectionGroup " type="Configs.MediaCommunications">
      <section name="settings" type="System.Configuration.ConfigurationSectionGroup, System.Configuration, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" allowLocation="true" allowDefinition="Everywhere" />
Can you help me please?

wrote Dec 9, 2017 at 1:48 PM