ConfigurationSettings can only read one <section>?

  • Thread starter Thread starter Keith Patrick
  • Start date Start date
K

Keith Patrick

I have a configuration file that has two <section>s defined, each with the
same class of custom section handler (although this doesn't matter; I've
tried two different kinds). If I read either one (multiple times, too), I
have no problems, but the second I read the other <section>, I get a
ConfigurationException saying that the runtime could not create an instance
of type "<customsectionhandler>". Is this some restriction to configuration
files that I'm missing? I couldn't find any reset method that may have been
of use, so I'm not seeing what I'm doing wrong.
 
I knew I was bound to figure it out if I posted the question. My paths
weren't prepended with "//", so on the 2nd section, I'm still in the
relative XPath of the prior configuration.
 
OK, that wasn't it. I've been able to narrow it down. Basically, my app is
running under heavy restrictions (I allow unrestricted access for
SecurityPermission, ReflectionPermission, and UIPermission only), so in that
scenario, I am allowed to configure a single <section> any other sections
read result in a violation of some kind in instantiating my object. I'm
working with permview and the stack trace to track down the permission that
I am lacking (the security exception is masked in a configuration
exception), but so far, it looks like a really weird one.
 
Found the cause, and it's a rather obscure one, so if anyone from MS reads
this, I would be interested in knowing the "why" on this one. Basically,
the first section read with ConfigurationSettings.GetConfig(...) is
free...no permissions necessary. The *2nd* section read requires at a
minimum FileIOPermission(SecurityAction.RequestMinimum, Read="<myUserDir>",
PathDiscover="<myUserDir>")

Could anyone offer me some insight as to why this anomaly exists? My only
real hypothesis is that to re-read the file to grab the next section
requires reinitializing the config file (although one would think that
config file reading would be an asserted permission). Closest I can come to
it is looking at the IL for where it occurs (it's the
ConfigurationException(string) throw) in ConfigurationRecord.GetFactory
 
-----Original Message-----
I have a configuration file that has two <section>s defined, each with the
same class of custom section handler (although this doesn't matter; I've
tried two different kinds). If I read either one (multiple times, too), I
have no problems, but the second I read the other
ConfigurationException saying that the runtime could not create an instance
of type "<customsectionhandler>". Is this some restriction to configuration
files that I'm missing? I couldn't find any reset method that may have been
of use, so I'm not seeing what I'm doing wrong.


.
Hello.Me too have problem with configuration files.I can
read a section but if I modifye it and the retry to read
I can't read anything.
 
Back
Top